LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

Instances produced with RegisterFallback factory are being disposed on ServiceContainer.Dispose()

Open dombrovsky opened this issue 4 years ago • 0 comments

class SomeDisposableClass : IDisposable
{
    public void Dispose() { }
}

var disposableInstance = new SomeDisposableClass();
_serviceContainer.RegisterFallback((serviceType, serviceName) => serviceType == typeof(SomeDisposableClass), request => disposableInstance);

_serviceContainer.Dispose();

In this example SomeDisposableClass instance would be disposed when LightInject container disposed. However it was not LightInject container who created the instance, so it should not be responsible for calling IDisposable.Dispose on it.

May be related to https://github.com/seesharper/LightInject/issues/538.

dombrovsky avatar Sep 18 '21 13:09 dombrovsky