Ninject, Bind should be .InRequestScope() OR .InSi

2019-03-19 03:25发布

I have Below code One is bindable to my User Repository and another for Cache. What scope should I use for UserRepository and Cache. Should Scope on UserRepository be Singleton?

    this.Bind<IUserRepository>().To<UserRepositary>().InRequestScope();

    this.Bind<IDistributedCacheService>().To<DistributedCacheService>().InSingletonScope();

1条回答
我只想做你的唯一
2楼-- · 2019-03-19 03:56

Usually the repositories are bound inrequestscope because that generally defines the unit of work or database transaction size.

Update: Here is a bit more information on managing critical resources using ninject. I ran into this while binding my repos inrequestscope.

http://bobcravens.com/2010/11/using-ninject-to-manage-critical-resources/

Bob

查看更多
登录 后发表回答