To start I'm using Ninject 1.5. I have two projects: Web project and a Class library. My DI configuration is within the Web project. Within my class library I have the following defined:
public interface ICacheService<T>
{
string Identifier { get; }
T Get();
void Set( T objectToCache, TimeSpan timeSpan );
bool Exists();
}
And then a concrete class called CategoryCacheService.
In my web project I bind the two:
Bind( typeof( ICacheService<List<Category>> ) ).To( typeof(CategoryCacheService)).Using<SingletonBehavior>();
In my class library I have extension methods for the HtmlHelper class, for example:
public static class Category
{ [Inject] public static ICacheService> Categories { get; set; }
public static string RenderCategories(this HtmlHelper htmlHelper) { var c = Categories.Get();
return string.Join(", ", c.Select(s => s.Name).ToArray()); } }
I've been told that you cannot inject into static properties, instead I should use Kernel.Get<>() - However... Since the code above is in a class library I don't have access to the Kernel. How can I get the Kernel from this point or is there a better way of doing this?
Thanks!