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
As of this writing, PerWebRequest lifestyle does not support resolving in Application_Start().
See issue description and discussion:
Workarounds for this particular case:
Register RegisterRoutes
as an instance, explicitly passing it the current context as constructor parameter, e.g.:
container.Register(Component.For()
.Instance(new RegisterRoutes(Context)));
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();
Then inject IServerMapPath
into your RegisterRoutes
.