DAL - &GT; BLL&LT; - GUI +组成的根。如何设置DI-的绑定? [英] DAL -> BLL <- GUI + composition root. How to setup DI-bindings?
问题描述
我已经做了三层应用程序与refrences打算在本<一个描述href=\"http://stackoverflow.com/questions/2358627/mef-separate-interface-assembly-leads-to-interface-for-every-class/2362397#2362397\">answer:
I have made a three-layer application with refrences going as described in this answer:
DAL with Repositories -> BLL with services and IRepository <- Asp.net mvc-app
要获得与依赖注入我看到几个选项此运行:结果
1.参考DAL从web应用程序添加到能够在应用程序启动的设置绑定。结果
2.使用XML配置结果的容器
(3.使用反射来加载DAL组装,找到类型)
To get this running with dependency injection I see a few options:
1. Add a reference to DAL from the web-app to be able to setup bindings on application start.
2. Use a container with xml-configuration
(3. Use reflection to load the dal-assembly and find types)
选项1是容易的,也使得DAL.dll被复制到斌后来我突然再次提出我辛辛苦苦摆脱的参考。存储库现在可以直接访问。选项2和3似乎是不必要的复杂。
Option 1. is easy and also makes the DAL.dll be copied to bin but then I suddenly reintroduce the reference I worked so hard to get rid of. The repositories can now be accessed directly. Option 2 and 3 seems unnecessarily complex.
难道就没有别的办法吗?
Is there no other way?
推荐答案
标记塞曼的回答给了我这个变种的理念是:
Mark Seemann's answer gave me the idea for this variant:
DAL with Repositories -> BLL with services and IRepository <- Asp.net mvc-app
^------------------------^--------- Composition Root <-------´
这是为了说明,而不是让Web项目中引用它引用一个单独的成分根项目,同时引用DAL和BLL的DAL。该组合物根项目有一个方法,定义绑定的类。它提供这些额外的好处:
This is meant to illustrate that instead of letting the Web project reference the DAL it references a separate Composition Root-project that references both DAL and BLL. The composition-root-project has a single class with one method that define the bindings. It gives these additional benefits:
- 只有三层。四层将是球队一个艰难的销售。
- 松耦合保证。这是不可能从取景code访问DAL。
- 更好的工具支持。控制器保持在标准位置,以便添加控制器是上下文菜单上访问和失踪的意见是在控制器 - code凸显。也没有必要来配置或编写自定义控制器工厂。
我看不出有什么大的缺点。
I don't see any big drawbacks.
这篇关于DAL - &GT; BLL&LT; - GUI +组成的根。如何设置DI-的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!