首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要帮助配置Castle-Windsor

需要帮助配置Castle-Windsor
EN

Stack Overflow用户
提问于 2010-05-03 00:37:04
回答 1查看 262关注 0票数 1

我将这些基本接口和提供程序放在一个程序集中(Assembly1):

代码语言:javascript
复制
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>();
    }
}

我在另一个程序集(Assembly2)中实现了这个功能:

代码语言:javascript
复制
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>();
    }
}

我希望能够从容器中获取IRead<Product>IProductDao。我正在使用这个注册:

代码语言:javascript
复制
container.Register(
    AllTypes.FromAssemblyNamed("Assembly2")
        .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(),
    AllTypes.FromAssemblyNamed("Assembly1")
        .BasedOn(typeof(IReadDao<>)).WithService.Base());

IReadDao<Product>运行得很好。容器给了我ProductDao。但是如果我试图获取IProductDao,容器就会抛出ComponentNotFoundException。如何正确配置注册?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-03 12:14:11

尝试更改您的Assembly2注册以使用所有接口:

代码语言:javascript
复制
AllTypes.FromAssemblyNamed("Assembly2").BasedOn(typeof(IReadDao<>))
  .WithService.Select((t, baseType) => t.GetInterfaces());
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2754125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档