castle PerRequestLifestyle not recognize

早过忘川 提交于 2019-12-01 05:48:27

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

See issue description and discussion:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!