question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On creating Startup, custom services do not resolves

See original GitHub issue

Describe the bug

I have a library for strongly typed IConfiguration wrapper, it works fine on 2.2, but in 3.0.0 GenericWebHostBuilder.UseStartup does not resolve custom services, already added to IServiceCollection to HostBuilder/WebHostBuilder at the moment Startup created using ActivatorUtilities.

For now used GenericWebHostBuilder.HostServiceProvider. It can resolve only IHostingEnvironment and IConfiguration.

To Reproduce

Complete example: https://github.com/phema-team/Phema.Configuration/tree/master/examples/Phema.Configuration.Example Steps to reproduce the behavior:

  1. Use builder.ConfigureServices((c, s) => s.AddSomeService())
  2. Use builder.ConfigureWebHostDefaults (call builder.ConfigureWebHost) and add Startup
  3. In Startup add SomeService to constructor

Expected behavior

All services added previously to IServiceCollection can be resolved in Startup creation

Screenshots

image image

Additional context

I think we should use in GenericWebHostBuilder.UseStartup for creating Startup all previously registered services passing IServiceProvider built from IServiceCollection parameter to GenericWebHostBuilder.HostServiceProvider. Logic the same, if IHostingEnvironment/IConfiguration resolve from WebHostBuilderContext, else try to resolve from already added services

I added pull request with potential fix https://github.com/aspnet/AspNetCore/pull/9296

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Tratchercommented, Apr 12, 2019
0reactions
Tratchercommented, Apr 16, 2019

This issue is closed, please follow the announcement issue instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve service while trying to activate Startup
If the startup class is where you add the IHttpContextAccessor service to the DI-container, it's impossible for startup to have it as a ......
Read more >
Dependency injection in ASP.NET Core
Services resolved from the container should never be disposed by the developer. If a type or factory is registered as a singleton, the...
Read more >
Code samples migrated to the new minimal hosting model ...
Learn how to migrate ASP.NET Core samples to the new minimal hosting model in 6.0.
Read more >
Reasons Not To Use A Custom Support Startup
One of the main reasons not to use a custom support startup is because they often lack the expertise necessary to provide quality...
Read more >
Custom Services
Services are add-ons that are created for reusable logic to simplify tests, manage your test suite and integrate results. Services have access to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found