【发布时间】:2013-10-31 14:00:42
【问题描述】:
鉴于以下接口和类,Autofac 中有没有办法
- 为所有具有
ProviderAttribute的类注册Provider<T>,其中T是此类的类型(考虑注册开放泛型并使用Autofac 的MakeGenericType()解析它们) - 将这些注册的提供者作为,鼓,
IEnumerable<IProviderBase>注入到其他类的构造函数中
概述:
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)
{
//...
}
}
【问题讨论】:
标签: autofac open-generics