LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

How to register an IDisposable instance that should outlive the container?

Open roy-t opened this issue 1 year ago • 0 comments

Short question that I couldn't find in the docs.

I have an instance of an object that implements IDisposable. Let's name it foo. When I use container.RegisterInstance<T>(foo) foo will, from then on, be owned by the container. When I call container.Dispose() foo will be disposed as well.

Is there a way to make sure foo outlives the container? Since it wasn't created by LightInject I also don't want LightInject to clean it up.

roy-t avatar Jun 15 '24 09:06 roy-t