UnitOfWork with NInject design issues

社会主义新天地 提交于 2019-12-12 17:17:17

问题


I have my UnitOfWork class in DataAccess project and to resolve my IUnitOfWork interface (with UnitOfWork class), I need to use Ninject to Bind the IUnitOfWork interface with UnitOfWork class in my web project.

To do this I need to refer my DataAccess project (which contains UnitOfWork class) in the Web project. Is this good design wise? I mean referring DataAccess in the web project seems to be a bad idea & I never did that.

So, please advise me on what to do?


回答1:


If you are not comfortable having reference to DataAccess project (imho it is not a big issue) you can create separate project (let's call it ModuleProject) that will contain NinjectModules. ModuleProject will have references to both DataAccess and to project where IUnitOfWork is defined. In your web project you will have reference to ModuleProject and use its classes to register modules.

Module

public class NinjectConfiguration : NinjectModule
{
    public override void Load()
    {
        Bind<IUnitOfWork>().To<UnitOfWork>();
    }
}

Registration in web project

kernel.Load(new Mod.NinjectConfiguration());

More information on modules here.



来源:https://stackoverflow.com/questions/15507915/unitofwork-with-ninject-design-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!