MVC3 应用程序中的 IoC 容器初始化
如果 MVC3 应用程序(示例项目名称 - SuperApp.Web)依赖于驻留在单独程序集 (SuperApp.Core) 中的业务逻辑,则 IoC 容器初始化是否仍发生在网站项目的代码中?
我知道网站实际上是一个应用程序,初始化控制会传递给它,但如果 .Core 项目的依赖项在其中得到解析,并使用它自己的 IoC 容器库引用,那就更合乎逻辑了。
我特别使用 Ninject,到目前为止,我已经看到所有初始化都是在应用程序“Start”方法中的 WebActivator 的帮助下完成的。站点项目是否可以免于 IoC,并让 BL dll 弄清楚它将要处理什么?
If an MVC3 application (an example project name - SuperApp.Web) is relying on a business logic that resides in a separate assembly (SuperApp.Core), is IoC container initialization still takes place in web site project's code?
I understand that web site is actually an application, and the initialization control is passed to it, but it would be more logical if a dependencies for a .Core project would be getting resolved in it, with it's own IoC container library reference.
I am using Ninject in particular, and so far I've seen all initialization done with the help of WebActivator in Applications "Start" method. Is it possible for a site project to be IoC free, and let the BL dll figure out what it's going to be working with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您可以考虑的事情之一是在 Core 项目中创建一个 ninject 模块,其中的绑定直接与核心相关。但是,您仍然需要在正在运行的应用程序中注册此模块,因此如果不管理 DI 容器,您就无法运行站点项目。这是因为您需要在构建控制器时插入 DI
One of the things you can look into for this is to create a ninject module in your Core project with the bindings relating directly to core. However you still need to register this module in your running application, so no you cant have your site project running without managing the DI container. This is because you need to plug your DI in at the construction of your controllers