我得到了IUnitOfWork
接口(我不会向你展示它的实现):
public interface IUnitOfWork : IDisposable
{
...
}
注意IDisposable
继承。此外,我得到了具有适当实现的服务:
public interface IBusinessLogicService
{
...
}
public sealed class BusinessLogicService : IBusinessLogicService
{
// Dependency is auto-injected by ninject
// because of the custom injection heuristic.
public IUnitOfWork UnitOfWork { get; set; }
...
}
我们去ninject绑定:
kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
kernel.Bind<IBusinessLogicService>().To<BusinessLogicService>();
如您所见,ninject 将IUnitOfWork
在请求结束时自动停用实例并释放它。
现在,问题是,
ninject 是否还会停用(并在下一个 Web 请求时重新激活)依赖于停用对象的实例(如IBusinessLogicService
) ?