Will this service will be disposed using DependencyInjection?
I have the following class which is added to the default DI-container (Blazor WASM)
and In my classes I simply do
the
TestClass
itself will be instantiated by the DI as well. Will the disposed method of the GrpcService will be called?2 Replies
It might be better to not use DI, just create instance within using scope if disposing is important for you. There is no other service dependency in ClientGrpcService so its easy to take it out from DI container
i guess you want to reuse the same
IClientGrpcService
instance across multiple other services?
then you could register it as a scoped service in DI and create/dispose a scope according to your needs
here is a article showing some further possibilities: https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#disposal-of-services