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?