When to use Singleton vs Transient vs Request using Ninject and MongoDB

后端 未结 3 1932
南笙
南笙 2020-12-31 01:58

I\'m not quite sure when I should use SingletonScope() vs TransientScope() vs RequestScope() when I do my binding in my global.cs file.

I have for example my call to

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 02:19

    From deleted question as requested by @shankbond above


    The Disposal is not necessarily performed synchronously on your main request thread as one might assume.

    You probably want to stash a Block and then Dispose() it at an appropriate phase in your request (how are you going to handle exceptions?)

    Have a look in the Ninject Tests for more examples (seriously, go look - they're short and clear and I didnt regret it when I listened the 3rd time I was told to!)

    See http://kohari.org/2009/03/06/cache-and-collect-lifecycle-management-in-ninject-20/

提交回复
热议问题