castle PerRequestLifestyle not recognize

前端 未结 2 1637
轻奢々
轻奢々 2021-01-13 08:04

New to Castle/Windsor, please bear with me.

I am currently using the framework System.Web.Mvc.Extensibility and in its start up code, it registered HttpContextBase l

相关标签:
2条回答
  • 2021-01-13 08:13

    Maby try to add it under Modules section, like here: IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

    http://www.jasonlinham.co.uk/2009/02/castle-and-iis7.html

    0 讨论(0)
  • 2021-01-13 08:18

    As of this writing, PerWebRequest lifestyle does not support resolving in Application_Start().

    See issue description and discussion:

    • http://support.castleproject.org/projects/IOC/issues/view/IOC-ISSUE-166
    • http://groups.google.com/group/castle-project-users/browse_thread/thread/d44d96f4b548611e

    Workarounds for this particular case:

    1. Register RegisterRoutes as an instance, explicitly passing it the current context as constructor parameter, e.g.:

      container.Register(Component.For<IBootstrapperTask>()
                                  .Instance(new RegisterRoutes(Context)));
      
    2. Use HostingEnvironment.MapPath instead of contextBase.Server.MapPath. Want to make it mockable? Use it through a simple interface, e.g.:

      interface IServerMapPath {
          string MapPath(string virtualPath);
      }
      
      class ServerMapPath: IServerMapPath {
          public string MapPath(string virtualPath) {
              return HostingEnvironment.MapPath(virtualPath);
          }
      }
      
      container.AddComponent<IServerMapPath, ServerMapPath>();
      

    Then inject IServerMapPath into your RegisterRoutes.

    0 讨论(0)
提交回复
热议问题