Skip to content

StopApplication shuts down host but not application #9198

@Hoffs

Description

@Hoffs

Describe the bug

When calling StopApplication() on IApplicationLifetime which is resolved from DI it only stops the host but application is kept alive and running.

To Reproduce

Using ASP.NET Core Web API template call StopApplication() on resolved interface in either controller or hosted service.
Startup:

        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();

Stopping, where _serviceProvider is IServiceProvider and IApplicationLifetime is Microsoft.Extensions.Hosting interface.

var lifetime = _serviceProvider.GetService(typeof(IApplicationLifetime)) as IApplicationLifetime;
lifetime.StopApplication();

Expected behavior

Entire application shuts down.

Additional context

This is happening on dotnet 2.2 using WebHost to start the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions