There is something like this, I will describe in a very schematic way:
Bind<IUnitOfWork>().To<UnitOfWork>(); Bind<ISomeService>().To<SomeService>(); class UnitOfWork : IUnitOfWork, IDisposable { public Dispose(){} } // Это что то вроде GodObject (прим. фасад, методы которого, дергают кнопочки из WinForms, существует пока существует форма, ) // IDisposable не реализует class SomeService : ISomeService { IUnitOfWork readonly _uow; public SomeService(IUnitOfWork uow) { this._uow = uow; } public void Method1() { this._uow.SomeAction1(); } public void Method2() { this._uow.SomeAction2(); } } The question is: how much reasonable is the decision to slap the solid IUnitOfWorkFactory (Ninject.Extensions.Factory) and implement the dependency instead of the constructor argument, with a factory, something like the following code:
Bind<IUnitOfWork>().To<UnitOfWork>(); // Здесь можно обозначить Scope, если реализации репозиториев зависят // от DbContext, и нужно сохранять один экземпляр на весь UnitOfWork // прим: Bind<IUnitOfWork>().To<UnitOfWork>().DefinesNamedScope("SingleDbContextScope"); // а DbContext биндить так: Bind<SomeDbContext>().ToSelf().InNamedScope("SingleDbContextScope"); Bind<IUnitOfWorkFactory>().ToFactory(); Bind<ISomeService>().To<SomeService>(); // Это что то вроде GodObject (прим. фасад, методы которого, дергают кнопочки из WinForms, существует пока существует форма, ) class SomeService : ISomeService { readonly IUnitOfWorkFactory _uowFuctory; public SomeService(IUnitOfWorkFactory uowFuctory) { this._uowFuctory = uowFuctory; } public void Method1() { using(var uow = _uowFuctory.Create()) { this.uow.SomeAction1(); } } public void Method2() { using(var uow = _uowFuctory.Create()) { this.uow.SomeAction2(); } } } Or there are some other solutions to this problem, and it looks like an injection through a factory, even if it is not solid, it is not a ctor injection at all