Disposing of ViewModels in Caliburn Micro and Castle Windsor

后端 未结 1 1668
你的背包
你的背包 2021-01-13 12:17

I\'m using Castle-Windsor as my container in a Caliburn-Micro Silverlight app. My ViewModel objects are reasonably chunky as they call WCF services and a bunch of other stuf

相关标签:
1条回答
  • 2021-01-13 13:03

    The lifecycle you want for each of your VM types is going to have an impact here, so there is not really a right answer for the context you have provided.

    The Screen base class of CM provides you with protected virtual void OnDeactivate(bool close); which is a good place to start. For your heavyweight VMs you should override this method, and if the VM is closing indicated by the close parameter, release any resources (WCF channels etc) that need to be disposed of, this would include disposing the resource (if IDisposable is relevant) and also disconnecting any references to it so that it can be cleaned up by the GC.

    I don't use Castle so I can't help you in terms of configuring lifecycles etc. But if you follow the above, you aren't going to be holding on to anything heavy weight. I assume that with the correct lifecycle configuration, Castle will clean up any old instances that you aren't going to use again itself without an explicit call to Release.

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