温莎城堡与 ASP.NET MVC 2 区域
潜伏了几个月,决定提出一个问题。总的来说,我对温莎和国际奥委会还很陌生。我可以让 Windsor 毫无问题地处理我的 MVC2 项目。我正在从事的项目是一个使用新区域概念的 MVC2 项目下的多个应用程序的“门户”。在这种情况下,每个区域实际上都是“门户”内的一个单独的应用程序。我们这样做是为了有效地共享大量通用代码、视图、身份验证和跨应用程序功能。我们的许多应用程序都相互链接,因此在讨论后将它们合并到一个项目中是有意义的。
我想知道如何做实际上允许不同的区域注入不同的具体类?根据我有限的理解,Application_Start 负责管理容器的构建并将其分配为控制器工厂。我不一定想在应用程序级别进行所有注入。我们有一个配置系统,每个区域的根目录下都有一个 config.xml,这些设置会覆盖任何根目录设置。我希望通过让区域的 config.xml 读取每个区域的注入(类似于 Webforms web.config 的继承,其中较低文件夹中的配置覆盖父文件夹中的设置)来继续这一趋势。
示例:我将有一个 ILogHandler,它需要不同的具体实现,具体取决于我所在的应用程序的哪个区域。因此,我需要根据我在应用程序中的位置注入不同的东西。
我可以使用工厂轻松地做到这一点,因为每个区域都可以拥有自己的一组工厂,但我试图借此机会了解 IoC 及其优点/缺点。任何帮助将不胜感激。
Been lurking for a few months and decided to jump in with a question. I am very new to Windsor and IoC in general. I can get Windsor to work with my MVC2 project with no problem. The project I am working on is a "portal" of multiple applications under one MVC2 project using the new Areas concept. In this scenario, each Area will actually be a separate application inside the "portal". We are doing this to effectively share a LOT of common code, views, authentication, and cross-application functionality. Many of our apps link to one another, so it made sense after discussing it to combine them into one project.
What I am wondering how to do is actually allow different Areas to inject different concrete classes? In my limited understanding, the Application_Start is governing building the container and assigning it as the controller factory. I don't necessarily want to do all the injection at the application level. We have a config system where we have a config.xml at the root of every Area and those settings override any root settings. I would like to continue that trend by having the injections for each Area be read by the Area's config.xml (an inheritance similar to Webforms web.config where the config in a lower folder overrides settings in a parent folder).
Example: I would have an ILogHandler which would need a different concrete implementation depending on which Area of the application I am in. So I would need to inject something different depending on where I am at in the application.
I can easily do this using factories since each area could have it's own set of factories, but I am attempting to take this opportunity to learn about IoC and what the benefits/drawbacks are. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅供参考 - 您绝对不能拥有特定区域的安全代码。例如,根据当前区域注入 [Authorize] 属性的工厂或调用程序可能会打开您的应用程序以进行攻击。
将此与 MyAreaBaseController 进行对比,您所在区域中的所有控制器都必须对其进行子类化。这里的[授权]属性(以及其他与安全相关的代码)是可以的,因为它们应用于类型并且独立于任何“区域”概念。
Just FYI - you absolutely must not have area-specific security code. For example, a factory or invoker which injects [Authorize] attributes depending on the current area could open your application to attack.
Contrast this with a MyAreaBaseController, which all controllers in your area must subclass. [Authorize] attributes (and other security-related code) here are OK since they're applied to the type and are independent of any concept of "area".