2

In my application each tenant has it's own StructureMap container.

At runtime, tenant instances may be shutdown or restarted. Is there any tidying up I should do (such as calling IContainer.Dispose) or should I just let Garbage Collection do it's job?

We do have a number of singleton instances that implement IDisposable. Ideally we should call Dispose on these prior to disposing the container. I know this is done automatically on a Nested Container but wasn't sure about a standard container?

Thanks,

Ben

Ben Foster
  • 34,340
  • 40
  • 176
  • 285

2 Answers2

5

You should call Dispose on your container, which will dispose cached instances for you.

Robin Clowers
  • 2,150
  • 18
  • 28
0

Call dispose on the containers.

You should never "just let the Garbage Collector do its job". See my response to this post to understand why:

Is it bad practice to depend on the garbage collector

Dave Black
  • 7,305
  • 2
  • 52
  • 41
  • I was using StructureMap inside of a TopShelf Windows service and every 2/3 times the deployment would fail and just hang. It turned out the cause was not disposing of the container. – wootscootinboogie Mar 19 '18 at 15:10