Attempting to use a marker interface fails with IEnumerable<>

May 23, 2012 at 5:16 PM

Hey Chaps,

I am attempting to mimic some stuff from Orchard CMS in my own app using unity..

Okay so what I am trying to do is this...

Lets say I have a marker interface called IDependency..

public interface IDependency{ }

I then have several interfaces hanging off of this...

public interface ICustomerService : IDependency { }

public interface ICustomerRepository : IDependency { }

and then have some classes too...

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) { }

What I have so far..


            var container = new UnityContainer();

                //.Include(If.Implements<IDependency>, Then.Register().As<IDependency>().UsingLifetime<PerResolveLifetimeManager>())
                .Include(t =>
                    typeof(IDependency).IsAssignableFrom(t), (type, builder) =>

                            foreach (var interfaceType in type.GetInterfaces()
                            .Where(itf => typeof(IDependency).IsAssignableFrom(itf))) {
                                builder = builder.RegisterType(interfaceType, type);


Im falling down on the injecting of an IEnumerable<T> in to my NicksSecondController... Any Ideas??

Cheers, Nick