Ninject,绑定应该是.InRequestScope()或.InSingletonScope() [英] Ninject, Bind should be .InRequestScope() OR .InSingletonScope()

查看:600
本文介绍了Ninject,绑定应该是.InRequestScope()或.InSingletonScope()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code一个是绑定到我的用户系统信息库,另一个用于高速缓存。我应该使用UserRepository和Cache什么范围。应该UserRepository范围是单身?

  this.Bind< IUserRepository>()到<&UserRepositary GT;()InRequestScope()。    this.Bind&所述; IDistributedCacheService方式>()到< DistributedCacheService方式>()InSingletonScope();


解决方案

通常情况下,仓库绑定inrequestscope因为一般定义工作或数据库交易规模的单位。

更新:这是在管理使用ninject关键资源提供更多的信息。我跑到这同时结合我的回购inrequestscope。

<一个href=\"http://blog.bobcravens.com/2010/11/using-ninject-to-manage-critical-resources/\">http://blog.bobcravens.com/2010/11/using-ninject-to-manage-critical-resources/

鲍勃

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

解决方案

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://blog.bobcravens.com/2010/11/using-ninject-to-manage-critical-resources/

Bob

这篇关于Ninject,绑定应该是.InRequestScope()或.InSingletonScope()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆