using System; using System.Collections.Generic; using System.Web.Http.Dependencies; using Ninject; namespace FHT.Agency.Web.Infrastructure { public class ApiNinjectResolver : IDependencyResolver { public static IKernel _kernel { get; private set; } public static void SetKernel(IKernel kernel) { _kernel = kernel; } public ApiNinjectResolver() { // _kernel.Unbind(); //ninjectKernel.Unbind(); AgentApiNinjectConfiguration.AddBindings(_kernel); //_kernel.Bind().ToConstant(GlobalConfiguration.Configuration).InCustomRequestScope(); //_kernel.Bind().To().InCustomRequestScope(); //_kernel.Bind().To().InCustomRequestScope(); //not working why>? https://github.com/ninject/Ninject.Web.WebApi/issues/19 } public IDependencyScope BeginScope() { return this; } public object GetServiceOrDie(Type serviceType) { return _kernel.Get(serviceType); } public object GetService(Type serviceType) { return _kernel.TryGet(serviceType); } public T GetService() { return _kernel.TryGet(); } public IEnumerable GetServices(Type serviceType) { return _kernel.GetAll(serviceType); } public void Dispose() { } } }