删除EF DBContext和基础设施层的耦合 [英] Remove coupling for EF DBContext and infrastructure layer

查看:189
本文介绍了删除EF DBContext和基础设施层的耦合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基础设施层定义了我的接口,使用依赖注入,但现在的问题,我如何在infrasturcure层和服务层中解决DBContext使用接口的依赖,而不添加引用EF dll。

I defined my interfaces in infrastructure layer, to use Dependency Injection, but now problem, how can i resolve dependency of DBContext using interface, without adding reference to EF dll, in infrasturcure layer and service layer.

推荐答案

如果您需要从应用程序中完全隐藏EF,则需要使用存储库模式,将EF隐藏在您的存储库后面并生成(或写入)POCO实体。

If you need to hide EF completely from your application, you will need to use the repository pattern, hide EF behind your repositories and generate (or write) POCO entities.

更务实,您可以使用IQueryable支持的通用存储库,这允许一个很好的开发和单元测试经验,但是选择取决于你。

If you're more pragmatic, you can use generic repositories with IQueryable support, which allows a great development and unit testing experience, but what to choose is up to you.

这篇关于删除EF DBContext和基础设施层的耦合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆