Skip to content

ResolveServiceProviderFactory should work with Minimal Hosting #31861

Closed
@shirhatti

Description

@shirhatti

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

Activity

javiercn

javiercn commented on Apr 16, 2021

@javiercn
Member

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

ghost

ghost commented on Apr 16, 2021

@ghost

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

DamianEdwards commented on Apr 26, 2021

@DamianEdwards
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

davidfowl commented on Apr 27, 2021

@davidfowl
Member

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

davidfowl commented on Apr 27, 2021

@davidfowl
Member

Actually we might still be able to do this.

self-assigned this
on Jun 13, 2021
ghost locked as resolved and limited conversation to collaborators on Jul 13, 2021
added
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
and removed on Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-hosting

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @davidfowl@DamianEdwards@shirhatti@javiercn@BrennanConroy

      Issue actions

        ResolveServiceProviderFactory should work with Minimal Hosting · Issue #31861 · dotnet/aspnetcore