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

ResolveServiceProviderFactory should work with Minimal Hosting #31861

Closed
shirhatti opened this issue Apr 16, 2021 · 6 comments
Closed

ResolveServiceProviderFactory should work with Minimal Hosting #31861

shirhatti opened this issue Apr 16, 2021 · 6 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-hosting
Milestone

Comments

@shirhatti
Copy link
Contributor

Tools like EF migration rely on Program.CreateDefaultBuilder() at build-time to build the service container and resolve services (like DbContext).

https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs

@shirhatti shirhatti mentioned this issue Apr 16, 2021
10 tasks
@javiercn
Copy link
Member

@shirhatti also Microsoft.AspNetCore.Mvc.Testing depends on that

@ghost
Copy link

ghost commented Apr 16, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@DamianEdwards
Copy link
Member

I'm wondering if we could use a startup hook to enable this somehow, rather than boilerplate code that must be in the app for it to work. Alternatively, could we use a source generator that's enabled by the invoking tool (e.g. dotnet ef) to generate the required pattern or hook somehow.

@davidfowl
Copy link
Member

davidfowl commented Apr 27, 2021

I had an idea that we could use a diagnostic source for this but that won't work since this pattern basically wants a public API that is callable.

EF - https://github.com/dotnet/efcore/blob/ac2bb48b10ecf1289b568a94b7a35e8075c6d787/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs#L49-L59
Testing -

protected virtual IHostBuilder CreateHostBuilder()
{
var hostBuilder = HostFactoryResolver.ResolveHostBuilderFactory<IHostBuilder>(typeof(TEntryPoint).Assembly)?.Invoke(Array.Empty<string>());
if (hostBuilder != null)
{
hostBuilder.UseEnvironment(Environments.Development);
}
return hostBuilder;
}

These rely on a callable entrypoint.

@davidfowl
Copy link
Member

Actually we might still be able to do this.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-hosting
Projects
None yet
Development

No branches or pull requests

6 participants