Skip to content

Instantly share code, notes, and snippets.

@gyuwon
Created March 18, 2014 02:27
Show Gist options
  • Save gyuwon/9612507 to your computer and use it in GitHub Desktop.
Save gyuwon/9612507 to your computer and use it in GitHub Desktop.
public class NinjectDependencyScope : IDependencyScope
{
private IKernel _kernel;
public NinjectDependencyScope(IKernel kernel)
{
Contract.Assert(kernel != null);
this._kernel = kernel;
}
public object GetService(Type serviceType)
{
return this._kernel.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return this._kernel.GetAll(serviceType);
}
public void Dispose()
{
this._kernel = null;
}
}
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
private IKernel _kernel;
public NinjectDependencyResolver(IKernel kernel)
: base(kernel)
{
this._kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(this._kernel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment