1
我有一個裝配這些基本接口和提供者(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 08:03:33