开发者

Need help configuring Castle-Windsor

开发者 https://www.devze.com 2022-12-29 02:14 出处:网络
I have these base interfaces and providers in one assembly (Assembly1): public interface IEntity { } public interface IDao

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

精彩评论

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

关注公众号