我对存储库模式和依赖注入非常陌生。几乎所有的仓库模式我已经遇到了某种GETALL()方法,像这样:存储过程的存储库模式
public interface IRepository<T>
{
IQueryable<T> GetAll();
// other CRUD methods here...
}
我有一个问题,实现了这个接口和GETALL()方法,因为我调用存储过程需要一个根据用户输入而改变的参数。我不想在存储库接口中添加一个临时方法,例如IQueryable<T> GetAll(string input);
。我也不想参数添加到构造,因为它看起来有点凌乱的对我说:
public class ConcreteRepository : IRepository<Entity>
{
string _storedProcedureInput;
public ConcreteRepository(string storedProcedureInput)
{
_storedProcedureInput = storedProcedureInput;
public IQueryable<Entity> GetAll()
{
// Call to stored procedure goes here passing in the
// _storedProcedureInput variable.
}
}
我还使用依赖注入,所以我必须绑定时一些动态输入要添加到构造:
Bind<IRepository<Entity>>().To<ConcreteRepository>().WithConstructorArgument(?)
有什么建议?
UPDATE:
我想重用IRepository接口。例如,在一个程序中,我使用EF4来实现GetAll()方法,而在另一个程序中,我使用标准的ADO.NET来调用上述示例中的存储过程。
你的代码看起来完全没问题,根据repostitory模式。 –