Hi,
It seems that when registering a service as SingletonPerKey, and the service implements IDisposable in aspnet core, it disposes per request, however instance is created only once.
Execution flow is as follows
- First request > initialize service (ctor) > execute > call
.Dispose()
- Second request > execute > call
.Dispose()
This is what i got
scope.Configure(c =>
{
c.Export<DataClientManager>().As<IDataClientManager>().Lifestyle.SingletonPerKey((scope, context) => "global");
});
public interface IDataClientManager
{
IDataClientManager Register(object type);
}
public class DataClientManager : IDataClientManager, IDisposable
{
private readonly HashSet<object> _instances = new HashSet<object>();
public IDataClientManager Register(object type)
{
_instances.Add(type);
return this;
}
public void Dispose()
{
}
}
This causes some services such as GQL to not work properly, as they will Dispose and next time round it will blow.
I expects that it only Dispose once the server shuts down in the case of singleton
Versions
- Grace 7.1.0
- Grace.AspNetCore.Hosting: 7.0.1
- NetcoreApp 2.2
I have a working sample as well if needed. Thanks!
Hi,
It seems that when registering a service as
SingletonPerKey, and the service implementsIDisposablein aspnet core, it disposes per request, however instance is created only once.Execution flow is as follows
.Dispose().Dispose()This is what i got
This causes some services such as GQL to not work properly, as they will
Disposeand next time round it will blow.I expects that it only Dispose once the server shuts down in the case of singleton
Versions
I have a working sample as well if needed. Thanks!