1 year ago

#388253

test-img

Will Comeaux

AutoFac - Resolve But Pass Specific Constructor Value

I need to scan an assembly and, for each type that implements some interface (let's say IFoo) I need to register it with the container for later resolution. Say I have an IFoo class that takes 2 parameters in an assembly

public class MyFooA : IFoo
{
   public MyFoo(SomeRandomObject o, ILogger logger)
   {
   }
}

I have already registered ILogger with the container, and I need to resolve IFoo from it, but at resolution, I need to provide SomeRandomObject o (this can't be in the container). I should only have one implementation for the IFoo so I don't need to specifically name it (at least not yet)

Also note that the implementation of IFoo is found via reflection and the number/type of parameters it has is unknown until it's found.

How do I register and resolve these?

Thanks!

autofac

0 Answers

Your Answer

Accepted video resources