我有以下的项目结构,这些都是独立的项目,我被告知要这样做,所以不是我的选择。
CORE
--Self Explanitory
DATA
--Contains EF 4.1 EDMX, POCO's Generic Repository Interface
DATAMapping
--Contains Generic Repository
Services
-- Contains nothing at the moment
MVC 3 Application
-- Self Explanitory这是我的问题。我一直在读到,让控制器节食是最佳实践,模型/视图模型应该是哑巴,因此引入了我的项目结构的服务层部分。现在的实际问题是:这是一种好的方法,还是我为自己创造了太多的工作?
因此,如果我想说在产品或类别或任何其他实体上有一些CRUD操作,那么存储库应该从服务层/业务逻辑层实例化?
请输入一些信息??
发布于 2011-04-02 23:18:04
就我个人而言,我的服务层只引用CRUD操作的通用和抽象存储库。例如,服务层构造函数可能如下所示:
public class MyService: IMyService
{
private readonly IFooRepository _fooRepo;
private readonly IBarRepository _barRepo;
public MyService(IFooRepository fooRepo, IBarRepository barRepo)
{
_fooRepo = fooRepo;
_barRepo = barRepo;
}
public OutputModel SomeBusinessMethod(InputModel input)
{
// ... use CRUD methods on _fooRepo and _barRepo to define a business operation
}
}控制器将简单地将一个IMyService放入他的构造函数并使用业务操作。
然后,一切都将由您选择的依赖注入框架连接起来。
https://stackoverflow.com/questions/5523959
复制相似问题