patvax
patvax

Reputation: 634

DryIoc matching Func arguments to specific dependencies of resolved service

I have the following simplified example:

var container = new Container();
container.Register<D>();
container.Register<C>();
var c = container.Resolve<Func<int, int, C>>()(2, 4);
Console.WriteLine($"{c.I1}, {c.I2}, {c.D.I}");
    
class C
{
    public int I1 { get; }
    public int I2 { get; }
    
    public D D { get; }
    
    public C(D d, int i1, int i2)
    {
        I1 = i1;
        I2 = i2;
        D = d;
    }
}

class D
{
    public int I { get; }
    
    public D(int i)
    {
        I = i;
    }
}

Output: 2, 4, 2

Expected output: 2, 4, 4

Now to explain exactly what I mean. In a class I can resolve a Func<int, int, C> wrapper and use it to create a C instance. However the arguments from Func<int, int, C> are iterated from the beginning for both C and D which means that D gets the first int. I want to know if there is a way configure the container so that D gets the second int. In other words I am looking for a possibility to tell the container for each service which parameters of the Func<int, int, C> it should use for each argument.

Can this be done? How?

Upvotes: 0

Views: 26

Answers (0)

Related Questions