Let's say I have an IService and two implementations ServiceA and ServiceB. Then let's assume that ServiceA has ClassA parameter in its constructor (among others) and ServiceB has ClassB parameter. I would then like to:
- Register services as follow:
containerBuilder.RegisterType<ServiceA>().AsImplementedInterfaces();
containerBuilder.RegisterType<ServiceB>().AsImplementedInterfaces();
- Register an instance of either
ClassAorClassB(this is decided in runtime). - When some other component wants
IService, autofac will provide one basing one what can be constructed, i.e. if it has aClassAobject in repository, it will construct and provideServiceAetc.
How can I achieve that? Note that ClassA and ClassB do not share common interface.