we created a WCF service that uses the Unity container to resolve instances to manage Exchange Server Powershell commands. We have defined the IExchangePowershell interface, which has a specific implementation that implements IDisposable. After some time, we encountered a problem that we could not run powershell commands anymore, as the server said that too many powershell sessions were already open. Looks like we never got rid of our powershell instances. The Powershell-specific Dispose () method will take care of closing the workspace and session. As soon as I call this in the repository methods, we no longer get errors.
((IDisposable)this.powershell).Dispose();
Now, of course, I donβt want to explicitly call dispose on every repository method. I thought unity could take care of that. Our WCF instance provider does this:
public void ReleaseInstance(InstanceContext instanceContext, object instance) { container.Teardown(instance); }
But it really doesnβt get rid of IExchangePowershell instances. Do you know how I can automatically dispose of these instances?
source share