[英]Attempting to use a marker interface fails with IEnumerable<>
我试图在我自己的应用程序中使用统一来模仿Orchard CMS中的一些东西。
好的,我想要做的就是这......
假设我有一个名为IDependency的标记接口..
public interface IDependency{ }
然后,我有几个接口挂在这...
public interface ICustomerService : IDependency { }
public interface ICustomerRepository : IDependency { }
然后也有一些课程......
public class CustomerService : ICustomerService {
public CustomerService(ICustomerRepository customerRepo){ }
}
public class SomOtherCustomerService : ICustomerService {
public CustomerService(ICustomerRepository customerRepo){ }
}
public class NicksController : Controller {
public NicksController(IEnumerable<ICustomerService> customerServices) { }
}
public class NicksSecondController : Controller {
public NicksSecondController(IEnumerable<ICustomerService> customerServices) { }
}
到目前为止我有什么..
var container = new UnityContainer();
container
.ConfigureAutoRegistration()
.ExcludeSystemAssemblies()
//.Include(If.Implements<IDependency>, Then.Register()
//.As<IDependency>().UsingLifetime<PerResolveLifetimeManager>())
.Include(t =>
typeof(IDependency).IsAssignableFrom(t), (type, builder) =>
{
builder.RegisterType(type);
foreach (var interfaceType in type.GetInterfaces()
.Where(itf => typeof(IDependency).IsAssignableFrom(itf))) {
builder = builder.RegisterType(interfaceType, type);
}
})
.ApplyAutoRegistration();
我正在向我的NicksSecondController注入一个IEnumerable ...任何想法?
干杯,尼克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.