Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Host restricts Startup constructor injection #353

Tratcher opened this Issue Apr 12, 2019 · 0 comments


None yet
1 participant
Copy link

Tratcher commented Apr 12, 2019

TLDR: The only types the generic Host supports for Startup constructor injection are IHostEnvironment, IWebHostEnvironment, and IConfiguration. Applications using WebHost are unaffected.

In 3.0 we've re-platformed the web stack onto the generic host library. You can see the change in Program.cs in the templates:


One key behavior change here is that Host only uses one dependency injection container to build the application, as opposed to WebHost that used one for the host and one for the app. As a result the Startup constructor no longer supports custom service injection, only IHostEnvironment, IWebHostEnvironment, and IConfiguration can be injected. This change was made to avoid DI issues such as duplicate singleton services getting created.


Inject services into Startup.Configure:
public void Configure(IApplicationBuilder app, IOptions<MyOptions> options)

[We'll add more based on requests for specific scenarios.]

See aspnet/AspNetCore#9337 for discussion.

@Tratcher Tratcher added this to the 3.0.0 milestone Apr 12, 2019

@aspnet aspnet locked as resolved and limited conversation to collaborators Apr 12, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.