Note that there are some explanatory texts on larger screens.

plurals
  1. POWpf PRISM disposable module
    primarykey
    data
    text
    <p>I'm having a WPF application that is divided into PRISM modules.</p> <p>I have a service that deals with some unmanaged resources, therefore it implements the IDisposable interface:</p> <pre><code>public class MyCacheService : IMyCacheService, IDisposable { ... } </code></pre> <p>I also have a CameraServicesModule which registers an IMyCacheService instance:</p> <pre><code>public class CameraServicesModule : IModule { public CameraServicesModule(IComponentsManager manager) { this.manager = manager; } public void Initialize() { ... var theCacheService = new MyCacheService(); this.manager.RegisterInstance(typeof(IMyCacheService), null, theCacheService); } } </code></pre> <p>The question is: how do I dispose of the service instance? I have to do it at the application closing, but right now the MyCacheService.Dispose() doesn't get called at the application shutdown (or any other point in time).</p> <p>Should the CameraServicesModule implement IDisposable, too? Like this:</p> <pre><code>public class CameraServicesModule : IModule, IDisposable { public CameraServicesModule(IComponentsManager manager) { this.manager = manager; } public void Initialize() { ... this.theCacheService = new MyCacheService(); this.manager.RegisterInstance(typeof(IMyCacheService), null, theCacheService); } public void Dispose() { this.theCacheService.Dispose(); } } </code></pre> <p>If so, the question is: how do I dispose of the module? If not, the question is: which way should I dipose the service of?</p> <pre><code> LocalFileSystemConfigurationManager configManager = new LocalFileSystemConfigurationManager(this.PathToSettings); ComponentsManager compManager = new ComponentsManager(configManager, null, null); </code></pre> <p>Note: even if my module does implement IDisposable, disposing the componentsManager or configurationManager does not dispose the module.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload