Ninject UnitOfWork confusion

百般思念 提交于 2019-12-02 08:46:09

I just do this:

kernel.Bind<IUnitOfWork>.To<EFUnitOfWork>().InRequestScope();

EFUnitOfWork.cs

public class EFUnitOfWork : DbContext, IUnitOfWork
{
    // your normal DbContext plus your IUnitOfWork members that delegate to EF context
}

Since EF already implements a form of Unit Of Work, this allows you to use a more generic interface for it, and inject it easily.

Also, you can implement the EF constructors for connection strings and just pass them to base constructors. Then you can use the Ninject .WithConstructorArgument() to configure the connection string using your AppSettings code.

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