我应该如何为 Unity 和 AutoMapper 实现 MVC Bootstrapper?
为我的 MVC 2 应用程序创建引导程序的最佳方法是什么?我正在使用 Unity 和 AutoMapper,并希望尽可能抽象它们的加载和配置。
一个不错的例子在这里(http://weblogs.asp.net/rashid/archive/2009/02/17/use-bootstrapper-in-your-asp-net-mvc-application- and-reduce-code-smell.aspx ),但是 UnityContainer 实现了 IDisposable,并且在该示例中它永远不会被清理。这(在Bootstrapper中配置Automapper违反了开闭原则? )也是一个不错的例子,但他也没有处理 Unity/Disposable 问题。
这是(http://www.dominicpetifer.co.uk/Blog/42/put-an-ioc-powered-bootstrapper-in-your-asp-net-mvc-application)另一个很好的例子,说明如何做了一个 Bootstrapper,但同样没有解决 Unity/Disposable 问题。
我考虑过将 Bootstrapper 对象保留在静态变量中并使其实现 IDisposable,但这听起来不对。
What is the best way to create a bootstrapper for my MVC 2 app? I'm using Unity and AutoMapper and want to abstract the loading and configuration of them as much as possible.
A decent example is here (http://weblogs.asp.net/rashid/archive/2009/02/17/use-bootstrapper-in-your-asp-net-mvc-application-and-reduce-code-smell.aspx
), but UnityContainer implements IDisposable and in that example it is never cleaned up. This (Configuring Automapper in Bootstrapper violates Open-Closed Principle?) is also a decent example, but he doesn't deal with the Unity/Disposable problem either.
Here's (http://www.dominicpettifer.co.uk/Blog/42/put-an-ioc-powered-bootstrapper-in-your-asp-net-mvc-application) another great example of how to do a Bootstrapper, but again doesn't address the Unity/Disposable issue.
I thought about keeping my Bootstrapper object around in a static variable and make it implement IDisposable, but that doesn't sound right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 Bootstrapper 类中保留对容器的引用,则可以将其处置在应用程序端。
或者您可以从引导程序返回容器,保留对其的引用并将其处置在应用程序端。
我想这取决于你的喜好。除此之外,问题中列出的任何引导示例都应该是引导应用程序的不错选择。
If you keep a reference to the container in the Bootstrapper class you can dispose it on application end.
Or you could return the container from your bootstrapper, keep a reference to it and dispose it on application end.
Depends on your preference I guess. Apart from that, any of the bootstrapping examples listed in the question should be a good pick for bootstrapping your application.