First off, I'm using Ninject 2.0
I have my master page which I would like to inject into but I'm not quite sure how. What I tried was created a class that derives from System.Web.Mvc.ViewMasterPage and then I create my properties:
[Inject]
public ICacheService<List<Category>> Categories { get; set; }
[Inject]
public IConfigurationSettings Config { get; set; }
When I run my page neither of the properties get set and are both null. Any ideas on why or example on how to do this? Thanks
-- Update
So I've done more research and it seems I need to resolve the objects within the class myself because Ninject does not intercept the creation of the class. So now my question is how do I create a resolver for my kernel? The above code is within a class library so I don't have a reference to the kernel. I tried the following: (slightly modified from http://www.codethinked.com/post/2009/10/07/Our-Biggest-Enemy-Isne28099t-Developers-Who-Refuse-To-Move-Forward-It-is-Developers-Who-Pretend-To-Move-Forward.aspx )
public class KernelResolver
{
private static IKernel _kernel;
public KernelResolver(IKernel kernel)
{
_kernel = kernel;
}
public static T Resolve<T>()
{
return _kernel.Get<T>();
}
}
and then registered:
Bind<KernelResolver>().ToSelf()
Yet kernel is null... I just need to see some examples but I can't find any or it could be that I'm so confused that I don't know what I'm looking for :\
Any help is much appreciated!