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();
Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
Pirzada
  • 4,685
  • 18
  • 60
  • 113

1 Answers1

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

DecimalTurn
  • 3,243
  • 3
  • 16
  • 36
rcravens
  • 8,320
  • 2
  • 33
  • 26