I am using my custom virtual provider in my ASP.Net MVC4 project. Let's call the provider MyVirtualPathProvider. The provider is registered in OnApplicationStarted method like this:
HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());
The method is part of Global.asax.cs. On the top of which I have the following:
public class MvcApplication : NinjectHttpApplication
Now, I would like to use [Inject] attribute to inject one of my services, just like this:
[Inject]
public ILogger Logger { get; set; }
In the custom virtual path provider I have overridden GetFile method where I would like to log something using the injected Logger:
public override VirtualFile GetFile(string virtualPath)
{
...
Logger.Log(...);
Unfortunately, the Logger is null therefore it does not work.
I have tried to pass the Logger as a parameter in the custom virtual path provider constructor, like this:
HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider(Kernel.Get<ILogger>()));
Unfortunately, it is not the way to go, because I have the warning: "warning CS0618: 'Ninject.Web.Common.NinjectHttpApplication.Kernel' is obsolete: 'Do not use Ninject as Service Locator'"
What have I done wrong? Please advise.