C#C
C#4y ago
florent

Will this service will be disposed using DependencyInjection?

I have the following class which is added to the default DI-container (Blazor WASM)
public class ClientGrpcService<TService> : IClientGrpcService<TService>, IDisposable where TService : class
{
    private readonly GrpcChannel _channel;
    private readonly TService _service;

    public ClientGrpcService()
    {
        _channel = GrpcChannel.ForAddress("https://localhost:7046");
        _service = _channel.CreateGrpcService<TService>();
    }

    public TService Service => _service;

    public void Dispose()
    {
        _channel.Dispose();
    }
}

and In my classes I simply do
public TestClass(IClientGrpcService<Example> service)
{
...
}

the TestClass itself will be instantiated by the DI as well. Will the disposed method of the GrpcService will be called?
Was this page helpful?