キャッスル/ウィンザーは初めてですが、ご容赦ください。
私は現在、フレームワークSystem.Web.Mvc.Extensibilityを使用しており、そのスタートアップ コードでは、次のように HttpContextBase を登録しました。
container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
私がやりたかったのは、動作を変更し、httpContextBase のライフスタイルを PerWebRequest に変更することです。
そのため、コードを次のように変更しました。
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
ただし、これを行うと、次のエラーが発生しました。
System.Configuration.ConfigurationErrorsException: Looks like you forgot to
register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
Add '<add name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"
/>' to the <httpModules> section on your web.config
と の下で<system.web>
実行し<system.webServer>
ましたが、それでも同じエラーが発生します。ヒントはありますか?
前もって感謝します。
アップデート
リクエストごとに追加されたコード ブロック
system.web.mvc.extensibility フレームワークには、HttpApplication を継承する extendedMvcApplication というクラスがあり、Application_start メソッドでは、BootStrapper.Execute() を呼び出します。このメソッドのこの実装は次のとおりです。
public void Execute()
{
bool shouldSkip = false;
foreach (IBootstrapperTask task in ServiceLocator.GetAllInstances<IBootstrapperTask>().OrderBy(task => task.Order))
{
if (shouldSkip)
{
shouldSkip = false;
continue;
}
TaskContinuation continuation = task.Execute(ServiceLocator);
if (continuation == TaskContinuation.Break)
{
break;
}
shouldSkip = continuation == TaskContinuation.Skip;
}
}
ご覧のとおり、IBootStrapperTask のリストをループして実行しようとします。たまたま、mvc アプリにルートを登録するタスクが 1 つあります。
public class RegisterRoutes : RegisterRoutesBase
{
private HttpContextBase contextBase;
protected override TaskContinuation ExecuteCore(IServiceLocator serviceLocator)
{
contextBase = serviceLocator.GetInstance<HttpContextBase>();
return base.ExecuteCore(serviceLocator);
}
protected override void Register(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
XmlRouting.SetAppRoutes(routes, contextBase.Server.MapPath("~/Configuration/Routes.xml"));
}
}
xml ファイルのサーバー パスを取得できるように、httpcontextbase オブジェクトを getInstance(resolve) する必要があることがわかります。