我将这些基本接口和提供程序放在一个程序集中(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>();
}
}我在另一个程序集(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>();
}
}我希望能够从容器中获取IRead<Product>和IProductDao。我正在使用这个注册:
container.Register(
AllTypes.FromAssemblyNamed("Assembly2")
.BasedOn(typeof(IReadDao<>)).WithService.FromInterface(),
AllTypes.FromAssemblyNamed("Assembly1")
.BasedOn(typeof(IReadDao<>)).WithService.Base());IReadDao<Product>运行得很好。容器给了我ProductDao。但是如果我试图获取IProductDao,容器就会抛出ComponentNotFoundException。如何正确配置注册?
发布于 2010-05-03 12:14:11
尝试更改您的Assembly2注册以使用所有接口:
AllTypes.FromAssemblyNamed("Assembly2").BasedOn(typeof(IReadDao<>))
.WithService.Select((t, baseType) => t.GetInterfaces());https://stackoverflow.com/questions/2754125
复制相似问题