views:

42

answers:

1

I have these base interfaces and providers in one assembly (Assembly1):

public interface IEntity
{
}

public interface IDao
{
}

public interface IReadDao<T> : IDao
    where T : IEntity
{
    IEnumerable<T> GetAll();
}

public class NHibernate<T> : IReadDao<T>
    where T : IEntity
{
    public IEnumerable<T> GetAll()
    {
        return new List<T>();
    }
}

And I have this implementation inside another assembly (Assembly2):

public class Product : IEntity
{
    public string Code { get; set; }
}

public interface IProductDao : IReadDao<Product> 
{
    IEnumerable<Product> GetByCode(string code);
}

public class ProductDao : NHibernate<Product>, IProductDao
{
    public IEnumerable<Product> GetByCode(string code)
    {
        return new List<Product>();
    }
}

I want to be able to get IRead<Product> and IProductDao from the container. I am using this registration:

container.Register(
    AllTypes.FromAssemblyNamed("Assembly2")
        .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(),
    AllTypes.FromAssemblyNamed("Assembly1")
        .BasedOn(typeof(IReadDao<>)).WithService.Base());

The IReadDao<Product> works great. The container gives me ProductDao. But if I try to get IProductDao, the container throws ComponentNotFoundException. How can I correctly configure the registration?

+1  A: 

Try changing your Assembly2 registration to use all interfaces:

AllTypes.FromAssemblyNamed("Assembly2").BasedOn(typeof(IReadDao<>))
  .WithService.Select((t, baseType) => t.GetInterfaces());
Mauricio Scheffer
Thank you! It worked perfectly!
Jonathas Costa

related questions