GithubHelp home page GithubHelp logo

Comments (7)

g7ed6e avatar g7ed6e commented on June 7, 2024 1

Indeed i just checked and ServiceProvider is internal in 1.1.1.
I also checked Microsoft.Extensions.DependencyInjection 2.1.1 (net461, netstandard2.0), ServiceProvider is public in this version, thus the disposal of the ServiceProvider can be trigger by user code.

I'm closing this issue as ServiceProvider lifetime management is not handled by this package.

from extensions-dependency-injection.

g7ed6e avatar g7ed6e commented on June 7, 2024

Both MVC and WebApi packages externalize the IServiceProvider lifetime management to the user as the IServiceProvider instance is injected by constructor. I checked the MVC/WebApi sample and noticed that the IServiceProvider instance is not disposed, thus singleton are not disposed too.
You should indeed be able to get singleton instances disposed by adding the below code in Global.asax.cs file.

public void Application_End()
{
    ServiceProviderConfig.ServiceProvider?.Dispose();
}

Could you please open a pull request to fix the sample ?

from extensions-dependency-injection.

jun1sfukui avatar jun1sfukui commented on June 7, 2024

ServiceProviderConfig.ServiceProvider?.Dispose() doesn't work because IServiceProvider doesn't have Dispose().

Would it be better to change the type of ServiceProviderConfig.ServiceProvider to ServiceProvider?

Any solutions?

from extensions-dependency-injection.

g7ed6e avatar g7ed6e commented on June 7, 2024

As you suggested you could change the type of the property in the sample to be able to call Dispose method of the user provided instance of IServiceProvider.

from extensions-dependency-injection.

jun1sfukui avatar jun1sfukui commented on June 7, 2024

Actually I have tried it but it didn't work because the ServiceProvider class didn't exist.

I think it because of the .NET Framework version of the sample projects are 4.5.2 and the using package version of Microsoft.Extensions.DependencyInjection is very old.

I'm sorry I don't have enough time to update all projects to the latest version and try it out.

from extensions-dependency-injection.

g7ed6e avatar g7ed6e commented on June 7, 2024

You need to install Microsoft.Extensions.DependencyInjection to get acces to the ServiceProvider type.

from extensions-dependency-injection.

jun1sfukui avatar jun1sfukui commented on June 7, 2024

Already installed it but the version is 1.1.1 because the packages.config of WebApi.Sample project references the very old version.
Microsoft.Extensions.DependencyInjection of version 1.1.1 seems to not publish the ServiceProvider class.

from extensions-dependency-injection.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.