RequestScope () and Kernel.Get <> in Ninject

If I define a binding in ninject c ReqeustScope()and then call Kernel.Get<T>in this type outside the query, what will be the scope of the permitted object?

+5
source share
1 answer

StandardScopeCallbacks, , HTTP. NULL. , HTTP null. , , .

[Test]
public void ServiceInRequestScopeIsImplicitTransientWhenHttpContextIsNull()
{
    var kernel = new StandardKernel();
    kernel.Bind<ServiceInRequestScope>().ToSelf().InRequestScope();

    Assert.That(HttpContext.Current, Is.Null);

    var service0 = kernel.Get<ServiceInRequestScope>();
    var service1 = kernel.Get<ServiceInRequestScope>();

    Assert.That(service0, Is.Not.SameAs(service1));
}
+10

All Articles