在企业环境中将 global.asax 部署到 sharepoint 2010 以启用 Unity DI 容器

发布于 2024-11-16 12:11:50 字数 1151 浏览 1 评论 0原文

在处理 SharePoint 项目时,我尝试使用 Unity 作为依赖项注入容器。

我让这个容器运行的第一个想法是使用 global.asax,如 P&P 最佳实践中所述:

http://webclientguidance.codeplex.com/releases/view/17134#DownloadId=43305

在这些最佳实践中,他们告诉你手动编辑global.asax文件,使其继承SPUnityHttpApplication。

<%@ Application Language="C#" Inherits="Unity.SharePoint.SPUnityHttpApplication" %>

在企业环境中手动编辑此文件不是一个选项,因为我们有多个环境 (DTAP),并且所有环境都有多个需要手动步骤的前端服务器。

我找不到任何使用功能或 wsp 或任何东西来部署 global.asax 文件的方法,因为 global.asax 位于 Web 应用程序根目录中,而 sharepoint 将其他文件部署到 /14 hive 文件夹中,因此您无法访问Web应用程序根目录。

我研究过的替代方案是 SharePointServiceLocator。这个内置功能几乎可以满足我的需求。但它只能解析具有默认构造函数的类。这样我就无法通过使用构造函数注入来链接解析我的所有实现。 我找到了一篇文章如何更改服务定位器以利用 Unity但如果您阅读评论,这似乎无法正常工作。

我的问题可以通过解决这两个主要问题之一来解决:

  • 不要在 global.asax 中安排统一,但是在哪里以及如何安排?
  • 在sharepoint中部署global.asax?可能的?

Working on a SharePoint project I'm trying to use Unity as a dependency injection container.

My first idea to get this container running is using the global.asax as described in the best practices by P&P:

http://webclientguidance.codeplex.com/releases/view/17134#DownloadId=43305

In these best practices they tell you to manually edit the global.asax file to make it inherit SPUnityHttpApplication.

<%@ Application Language="C#" Inherits="Unity.SharePoint.SPUnityHttpApplication" %>

Manually editing this file is not an option in enterprise environments since we have multiple environments (DTAP) and all of them have multiple frontend servers that would need manual steps.

I can't find any way to deploy a global.asax file by using a feature or wsp or anything because the global.asax is located in the web application root and sharepoint deploys other files to the /14 hive folder so you can't acces the web application root directory.

Alternatives i've looked into is the SharePointServiceLocator. this build in functionality does almost what i want. but it can only resolve classes that have a default constructor. this way i can't chain resolve all my implementations by using constructor injection. I found a post how to change the service locator to make use of unity but this doesn't seem to work properly if you read the comments.

My problem can be fixed by fixing 1 of these 2 main problems:

  • Don't arrange unity in the global.asax, but then where and how?
  • Deploy the global.asax in sharepoint? possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

衣神在巴黎 2024-11-23 12:11:50

由于问题中描述的部署问题,global.asax 似乎不是执行此操作的最佳解决方案。

一个可行的解决方案是在 httpmodule 中实现此功能,

可以使用 init 方法连接所有内容,因为这是在共享点应用程序启动时调用的。

可以通过功能将 httpmodule 添加到 web.config 中这样

,就不需要对位于无法使用功能部署到的目录中的 global.asax 进行欺骗,并且您拥有实例化 DI 容器的所有功能和正确的时间。

The global.asax doesn't seem to be the best solution to do this because of the deployment issues described in the question.

A viable solution is implementing this in a httpmodule

The init method can be used to wire everything up since this is called when the sharepoint application starts.

the httpmodule can be added in the web.config by a feature receiver

This way there is no need to do tricks with the global.asax that is located in a directory you can't deploy to with a feature and you have all the functionality and correct time to instantiate the DI container.

眼眸 2024-11-23 12:11:50

它可能并不理想,但您可以考虑使用功能接收器并编写代码来直接编辑现有文件。

It may not be ideal, but you could look at using a feature receiver and write code to edit the existing files directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文