【问题标题】:Ninject, Bind should be .InRequestScope() OR .InSingletonScope()Ninject,Bind 应该是 .InRequestScope() OR .InSingletonScope()
【发布时间】:2011-05-20 18:41:21
【问题描述】:

我有下面的代码一个可绑定到我的用户存储库,另一个可绑定到缓存。我应该为 UserRepository 和 Cache 使用什么范围。 UserRepository 的 Scope 应该是 Singleton 吗?

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

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

【问题讨论】:

    标签: asp.net-mvc-3 ninject-2


    【解决方案1】:

    通常将存储库绑定在请求范围内,因为这通常定义了工作单元或数据库事务大小。

    更新:这里有更多关于使用 ninject 管理关键资源的信息。我在绑定我的 repos inrequestscope 时遇到了这个问题。

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

    鲍勃

    【讨论】:

    • 修复了链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2020-02-21
    • 2011-10-18
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多