问题
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 NinjectModule
s. 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