Need help configuring Castle-Windsor

Posted by Jonathas Costa on Stack Overflow See other posts from Stack Overflow or by Jonathas Costa
Published on 2010-05-02T16:37:03Z Indexed on 2010/05/02 16:48 UTC
Read the original article Hit count: 163

Filed under:

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?

© Stack Overflow or respective owner

Related posts about castle-windsor