开发者

Need help configuring Castle-Windsor

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 assem开发者_如何学Gobly (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?


Try changing your Assembly2 registration to use all interfaces:

AllTypes.FromAssemblyNamed("Assembly2").BasedOn(typeof(IReadDao<>))
  .WithService.Select((t, baseType) => t.GetInterfaces());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜