【发布时间】:2017-07-07 12:10:13
【问题描述】:
我正在使用不同的继承类,我希望从同一接口继承此类名称
public class CollectorA : ICollector
{
public string CollectSomething()
{
//DO Something
}
}
public class CollectorB : ICollector
{
public string CollectSomething()
{
//DO Something
}
}
我想做这样的事情:
public void Init(IServiceCollection serviceCollection)
{
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsInstanceOfType(typeof(ICollector)));
获取类型返回 null 我试过 AppContext 但还是不行。
foreach(var item in types)
{
serviceCollection.AddTransient<ICollector,item.Name>();
}
【问题讨论】:
标签: c# asp.net inheritance asp.net-core