# How to use a DI container when working with symfony/console commands?

**URL:** <https://discourse.slimframework.com/t/how-to-use-a-di-container-when-working-with-symfony-console-commands/5982>\
**Category:** Questions\
**Created:** [September 5, 2024, 6:12am UTC](https://discourse.slimframework.com/t/how-to-use-a-di-container-when-working-with-symfony-console-commands/5982 "2024-09-05T06:12:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bezlepkin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/bezlepkin/32/1653_2.png) [@Bezlepkin](https://discourse.slimframework.com/u/Bezlepkin)\
**Post date:** [September 5, 2024, 6:12am UTC](https://discourse.slimframework.com/t/how-to-use-a-di-container-when-working-with-symfony-console-commands/5982/1 "2024-09-05T06:12:19Z")

</div>

Hi! I’m trying to do a console command to create a user.

I connected symfony/console according to the following example:  
[https://odan.github.io/slim4-skeleton/console.html](https://odan.github.io/slim4-skeleton/console.html)

But I don’t understand how to access the ID container inside my command:

 ![2024-09-05_09-11-57](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/0/041dbdf59801a8005f2187bc6385f196f5116acc.png)

---

<div class="post-metadata">

**Author:** ![aaronfc](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/aaronfc/32/1650_2.png) [@aaronfc](https://discourse.slimframework.com/u/aaronfc)\
**Post date:** [September 5, 2024, 6:10pm UTC](https://discourse.slimframework.com/t/how-to-use-a-di-container-when-working-with-symfony-console-commands/5982/2 "2024-09-05T18:10:47Z")

</div>

Hi Bezlepkin!

If you have followed the guide you linked ([Console | Slim 4 Skeleton](https://odan.github.io/slim4-skeleton/console.html)) all you need to do to get your dependencies is to define a constructor with them.

In your example you could add a constructor like:

```auto
	private SomeDependencyClass $someDependency;

	public function __construct( SomeDependencyClass $someDependency)
	{
		parent::__construct();

		$this->someDependency = $someDependency;
	}

```

And then you can use it inside your `execute()` function like:

```auto
    $this->someDependency->doSomething();

```

Hope that’s clear and I understood your question!

---

<div class="post-metadata">

**Author:** ![Bezlepkin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/bezlepkin/32/1653_2.png) [@Bezlepkin](https://discourse.slimframework.com/u/Bezlepkin)\
**Post date:** [September 6, 2024, 9:06am UTC](https://discourse.slimframework.com/t/how-to-use-a-di-container-when-working-with-symfony-console-commands/5982/3 "2024-09-06T09:06:59Z")

</div>

> [@aaronfc](#):
>
> ```auto
> public function __construct( SomeDependencyClass $someDependency)
> {
> parent::__construct();
> 
> $this->someDependency = $someDependency;
> }
> 
> ```

It works! 😀  
Why didn’t I think of that myself?! 🤣
