我正在尝试将依赖注入引入现有的 Web 窗体应用程序。该项目被创建为一个网站项目(而不是一个 Web 应用程序项目)。我已经看到您在 global.asax.cs 中创建全局类的示例,它看起来像这样:
public class GlobalApplication : HttpApplication, IContainerAccessor
{
private static IWindsorContainer container;
public IWindsorContainer Container
{
get { return container; }
}
protected void Application_Start(object sender, EventArgs e)
{
if (container == null)
{
container = <...>
}
}
但是在一个网站项目中,如果你要求添加一个全局类,它只会添加包含服务器端脚本标签的 global.asax:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
我似乎没有办法从这里的 HttpApplication(和 IContainerAccessor)派生。还是我错过了一些明显的东西?