Guidelines For Dispose() and Ninject

前端 未结 1 958
情深已故
情深已故 2020-12-01 15:56

So, I have a method exposed from a WCF service as such:

public GetAllCommentsResponse GetAllComments(GetAllCommentsRequest request)
{
    var response = new          


        
相关标签:
1条回答
  • 2020-12-01 16:12

    The CLR documentation states that whoever creates a Disposable object is responsible for calling Dispose. In this case the object is created by Ninject. That means you should not call Dispose explicitly.

    Ninject disposes every Disposable object that has another scope other than InTransientScope as soon as the scope object to which the created object is tied is collected by GC. That's why every Disposable object should be Bindd with a scope that is not InTransientScope(). E.g. you can use InParentScope() from the NamedScope extension which will Dispose the object as soon as the object it is injected into is garbage collected.

    0 讨论(0)
提交回复
热议问题