title: Register generic ICacheManager using an IoC container (Ninject)
body: <p>This is for the <a href="https://github.com/MichaCo/CacheManager" rel="nofollow">CacheManager</a> library by Michah Conrad. In his example, he creates a cache manager using the CacheFactory.Build method, as seen here:</p>
  
  <pre><code>public class WebApiApplication : System.Web.HttpApplication
  {
      protected void Application_Start()
      {
          GlobalConfiguration.Configure(WebApiConfig.Register);
          var container = new UnityContainer();
          GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
          var cache = CacheFactory.Build("todos", settings =&gt;
          {
              settings
                  .WithSystemRuntimeCacheHandle("inprocess");
          });
          container.RegisterInstance(cache);
      }
  }
  </code></pre>
  
  <p>My question, is it possible to register the ICacheManger interface so that any property dependencies of any type will be automatically created by the IoC container?</p>
  
  <p>Say I have this class</p>
  
  <pre><code>public class MyClass
  {
      [Inject]
      public ICacheManager&lt;string&gt; StringCacheManager { get; set; }
  
      [Inject]
      public ICacheManager&lt;int&gt; IntCacheManager { get; set; }
  }
  </code></pre>
  
  <p>How could I set up my Ninject kernel to bind the generic ICacheManager interface so that it resolves using the types in MyClass?</p>
  
  <p>Something like this, but that actually works:</p>
  
  <pre><code>kernel.Bind&lt;ICacheManager&lt;T&gt;&gt;().ToMethod((context) =&gt;
  {
      return CacheFactory.FromConfiguration&lt;T&gt;("defaultCache");
  });
  </code></pre>