Skip to content

Non-conforming container support in Minimal APIs #41863

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

Open
1 task done
dotnetjunkie opened this issue May 26, 2022 · 4 comments
Open
1 task done

Non-conforming container support in Minimal APIs #41863

dotnetjunkie opened this issue May 26, 2022 · 4 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Milestone

Comments

@dotnetjunkie
Copy link

dotnetjunkie commented May 26, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I've been trying to write documentation on how Simple Injector users can integrate with the new ASP.NET Core Minimal API model, but it seems the injection of services into Minimal API map delegates is tight to the built-in DI abstraction, without the existence of an abstraction of some sort (such as MVC's IControllerActivator) to replace to hook into the pipeline.

The documentation shows the following example where Service is injected into the delegate and resolved from the configuration system:

app.MapGet("/{id}", ([FromRoute] int id,
                     [FromQuery(Name = "p")] int page,
                     [FromServices] Service service,
                     [FromHeader(Name = "Content-Type")] string contentType) 
                     => {});

Context

Simple Injector is a so-called "non-conforming" DI Container, meaning that it doesn't replace the built-in DI Container, but instead lives side-by-side the built-in container. Where the built-in container is used to resolve framework and third-party components, Simple Injector is used by the application developer to resolve their application components. This concept of non-conforming containers should be well-known within Microsoft, for instance from former discussions such as #30115, #29194, #28957, #14585, #8886 and aspnet/DependencyInjection#334.

Describe the solution you'd like

The introduction of an interception point that would allow non-conforming containers (and other interested parties) to intercept the creation of dependencies that are injected into Minimal API maps.

@javiercn javiercn added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label May 26, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone May 26, 2022
@ghost
Copy link

ghost commented May 26, 2022

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. 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.

@dotnetjunkie
Copy link
Author

I'd like @davidfowl to chime in on this one.

I might be overlooking an existing extension point here that can be used to achieve this. David, do you know of any extensibility point that we can use to achieve this? Your feedback is appreciated.

Cheers

@davidfowl
Copy link
Member

Minimal APIs are very efficient in the way code is generated to fill in parameter. There's no abstraction and we basically generate the code you would have hand rolled yourself to bind each of the known parameter types. There are a few paths forward here:

  • Simple injector would support a new type for binding from it's container. This type would can implement BindAsync on a type and support .e.g:
    class FromSimpleInjector<T>
    {
        public FromSimpleInjector(T service) => Service = service;
        public T Service { get; }
        
        // This will get called when the parameter is bound
        public static FromSimpleInjector<T> BindAsync(HttpContext context) => new(context.RequestServices.GetRequiredService<Container>().Resolve<T>());
    }
  • In .NET 7 there's route handler filters and Extend the ability to customize parameter binding for Minimal APIs #35489 that will make this a little smoother

@ghost
Copy link

ghost commented Oct 11, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. 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.

@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jun 20, 2023
@captainsafia captainsafia modified the milestones: .NET 8 Planning, Backlog Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Projects
None yet
Development

No branches or pull requests

5 participants