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

Can't Register Instance of IStartup in Generic Host #2732

Closed
thefringeninja opened this issue Nov 29, 2019 · 3 comments
Closed

Can't Register Instance of IStartup in Generic Host #2732

thefringeninja opened this issue Nov 29, 2019 · 3 comments
Milestone

Comments

@thefringeninja
Copy link

According to aspnet/Hosting#333 the following used to be sufficient to use an instance of an IStartup when starting kestrel:

internal static class WebHostBuilderExtensions {
  public static IWebHostBuilder UseStartup(this IWebHostBuilder builder, IStartup startup) =>
    builder.ConfigureServices(services => services.AddSingleton(startup));
}
_host = new WebHostBuilder()
  .UseKestrel()
  .UseStartup(new MyStartup(someDep))
  .Build();

However, using the new generic hosting bits, this no longer works.

_host = Host.CreateDefaultBuilder()
  .ConfigureWebHost(builder => builder
    .UseKestrel()
    .UseStartup(new MyStartup(someDep)))
  .Build();

crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
      Application startup exception
System.InvalidOperationException: No application configured. Please specify an application via IWebHostBuilder.UseStartup, IWebHostBuilder.Configure, or specifying the startup assembly via StartupAssemblyKey in the web host configuration.

@analogrelay
Copy link

To be clear, is UseStartup implemented the same way in the generic host model (by registering it in DI)? That doesn't work in generic host, we no longer use DI to resolve the startup class (the container doesn't exist yet).

@analogrelay analogrelay added this to the Discussions milestone Dec 2, 2019
@analogrelay
Copy link

dotnet/aspnetcore#11050 is tracking work on finding alternatives to IStartup in generic host.

@analogrelay
Copy link

Closing inactive discussion thread.


Note: Inactive closed issues are locked after 30 days since we don't triage closed issues and new comments tend to be lost. Feel free to post a new issue if this issue is locked and you have further questions/discussions. See our issue management policies for more details.

@ghost ghost locked as resolved and limited conversation to collaborators May 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants