【发布时间】:2011-05-10 04:52:02
【问题描述】:
在我的特定存储库类中,例如 CollectionRepository,我继承了通用基类 (BaseRepository),并在构造函数中使用了应该注入的基 UnitOfWork。但是,我无法访问任何 BaseRepository 继承的方法。
完全没有想法,任何帮助将不胜感激。
这里有一些代码来说明我的问题:
我的存储库被注入的控制器。
public readonly ICollectionRepository _collectionRepository;
public HomeController(ICollectionRepository collectionRepository, IRepository<Collection> repository)
{
_collectionRepository = collectionRepository;
}
public ActionResult Index()
{
_collectionRepository. //Here i only get the ICollectionRepositoryMethods
return View(new List<Note>());
}
我的基础仓库:
public class BaseRepository<T> : IRepository<T> where T : IAggregateRoot
{
public readonly IUnitOfWork _unitOfWork;
public BaseRepository(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public BaseRepository()
{}
public void Save(T Entity)
{
_unitOfWork.Session.Save(Entity);
}
}
继承基础的特定存储库类。
public class CollectionRepository : BaseRepository<Collection>, ICollectionRepository
{
public CollectionRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
public IList<Collection> GetTodaysCollections()
{
throw new System.NotImplementedException();
}
}
我正在使用结构映射像这样配置 CollectionRepository,不确定这是否正确:
For<ICollectionRepository>().Use<CollectionRepository>();
【问题讨论】:
标签: c# inheritance repository-pattern structuremap