Given the following interfaces and classes, is there a way in Autofac to
- Register a
Provider<T>
for all classes that have aProviderAttribute
, withT
being the type of such a class (Think registering open generics and resolving them with Autofac'sMakeGenericType()
) - Inject these registered providers as, drum roll,
IEnumerable<IProviderBase>
into the constructor of other classes
Overview:
public class ProviderAttribute : Attribute { }
public interface IProviderBase
{
Type Type { get; }
}
public interface IProvider<T> : IProviderBase
{
DoSomething(T t);
}
public class Provider<T> : IProvider<T>
{
public Type Type
{
get { return typeof (T); }
}
public DoSomething(T t)
{
//...
}
}
I have come up with a crude solution: