Я пытаюсь имитировать некоторые вещи из Orchard CMS в моем приложении, используя единицы ..Попытка использовать интерфейс маркер не может с IEnumerable <>
Хорошо, так что я пытаюсь сделать это ...
Допустим, у меня есть интерфейс маркер под названием 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();
Im падение вниз на инъекционное IEnumerable в моей NicksSecondController ... Любые идеи ??
Cheers, Ник