在正常的类库项目中,在何处连接 DI 与 Castle
我读到 Windsor 是最好用的 DI/IOC 工具,所以我想我应该尝试一下。我看到了许多如何使用 MVC 项目连接所有内容的示例,但是我需要使用 DDD 模型的其他层连接一些依赖关系映射。
我有一个需要注入 DbContext 的存储库库。我有一个从 DbContext 派生的类,因此这将是需要注入的类。更好的是,我可以为它制作一个界面。 IAppDBContext
。
正如我之前所说,所有示例的连接都发生在 Web 项目的 Global.asax 文件中。在普通的类库项目中我应该在哪里连接?
I have read that Windsor is the best DI/IOC tool to use so I figured I would give it a try. I am seeing many examples of how to wire everything up using and MVC project however I need to wire up some dependency mappings using other layers of my DDD model.
I have a repository base that needs to have DbContext injected. I have a class that derives from DbContext so that will be the class that needs to be injected. Better yet, I can make an interface for it. IAppDBContext
.
Like I said before all of the samples have the wiring taking place in the Global.asax
file of the web project. Where would I wire things up in a normal class library project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望在应用程序入口点引导容器。如果您正在编写可重用库,那么设置 IOC 容器不应该是它的责任,而是它的用户的责任。如果多个应用程序使用此库,它们肯定会需要独立的容器配置。
Probably you will want to bootstrap your container on application entry point. If you are writing reusable library, setting up IOC container shouldn't be its responsibility, but rather its users. If several applications use this library, they will surely want their independent container configuration.