Ninject、Bind 应该是 .InRequestScope() 或 .InSingletonScope()

发布于 2024-10-06 04:42:33 字数 315 浏览 1 评论 0原文

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

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

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

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找我们的幸福 2024-10-13 04:42:33

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

更新:以下是有关使用 ninject 管理关键资源的更多信息。我在将我的存储库绑定到 requestscope 时遇到了这个问题。

http://bobcravens.com/2010/11/using -ninject-to-manage-ritic-resources/ [存档]

鲍勃

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文