Dependency Injection Container: Multiple instances of a single class
<p>I am just starting with Dependency Injection Containers, and I am having a problem that makes my code messy. Let's take an example: I have a simple Container class that manages multiple services, a service can be "marked" as shared so it can only make one single instance.</p>

<p>So for example, I will make a simple (It's not the one I actually use) dependency injection container for, let's say, a User class, I would do so:</p>

<pre><code>class Container
{
    protected $parameters;

    public function set($index, $value)
    {
        $this-&gt;parameters[$index] = $value;
    }

    public function getUser()
    {
        return new User($this-&gt;paramaters['id'], $this-&gt;parameters['nickname']);
    }
}

$container = new Container();
$container-&gt;set('id', 1);
$container-&gt;set('nickname', 'Bob');
$container-&gt;getUser();
</code></pre>

<p>This works fine. But now, here is an other case: Let's say that now, instead of a User class, I want a Post class, for each post, I will need to set their title, text and date in the constructor, and each post shouldn't have the same parameters. In this case, is an dependency injection container adapted, if so, how should I achieve it without having a mess of a code?</p>

<p><strong>Edit:</strong></p>

<p>Will asked me my use case:</p>

<p>In my use case, I am actually doing this with a <strong>Router</strong> class that need to use <strong>Route</strong> instances. Each instantiated <strong>Route</strong> need to be passed two arguments: the <em>pattern</em> and the <em>callback</em>. So each time I ask my container to create a Route instance, it shouldn't use for all <strong>Route</strong>s the same pattern and callback, but a new pair of them (pattern + callback). How should I do so?</p>