unity.mvc3 和 ntier 应用程序中的工作单元?
慢慢地将MVC应用程序与类库放在一起:MVC>服务> I存储库> EF 存储库。目前,我的 EFRepository 实现都在其构造函数中创建一个新的 dbContext,但这会阻止测试,因此我需要注入 dbContext。
我在应用程序的其余部分成功地使用 unity.mvc3 进行 DI,但对如何正确实现 dbContext 注入感到困惑。
- dbContext 是否充当工作单元?
- 将 dbContext 注入存储库是否正确?
- 我是否正确地认为 dbContext 需要根据请求实例化?
我想我只是有点迷失了从这里该去哪里。我认为我应该有一个工作单元,但在我看来这会发生在服务层。
感谢所有帮助,
詹姆斯
Slowly putting an MVC app together with class libraries: MVC > Services > IRepository > EFRepository. Now at the moment, my EFRepository implementations each create a new dbContext in their constructor but this prevents testing so I need to inject the dbContext instead.
I am successfully using unity.mvc3 for DI throughout the rest of my app but am confused as to how to correctly implement the dbContext injection.
- Does a dbContext act as a Unit of Work?
- Is it correct to inject a dbContext into a Repository?
- Am I right in thinking that a dbContext needs to be instantiated per request?
Think I'm just a bit lost on where to go from here. I was thinking that I should have a Unit of Work but it seems to me this would happen at the service layer.
All help appreciated,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)