Ninject, Bind should be .InRequestScope() OR .InSingletonScope()
Asked Answered
H

1

12

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();
Handstand answered 6/12, 2010 at 4:28 Comment(0)
E
14

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/ [Archive]

Bob

Equilibrant answered 6/12, 2010 at 4:38 Comment(1)
Fixed the link.Equilibrant

© 2022 - 2024 — McMap. All rights reserved.