Consider the following classes and interfaces:
interface IFactory<T>{}
class Factory<T> : IFactory<T>{ }
interface IEntity{}
class Entity : IEntity{ }
I would like Autofac to resolve IFactory<IEntity>
to Factory<Entity>
like this:
b.RegisterType<Factory<Entity>>().As<IFactory<IEntity>>();
But I get the following exception (abbreviated for clarity):
The type 'Factory`1[Entity]' is not assignable to service 'IFactory`1[[IEntity]]'
Why is that and how can the issue be resolved? Or am I trying something "wrong"?
I briefly looked into RegisterGeneric
, but I don't think it applies here; also, because the above is just an example. In other cases I may want to define a different component for IFactory<IEntity>
.