dotnet / dotnet/aspnetcore

Non-conforming container support in Minimal APIs

Open
#41,863 4 comments 4 reactions 1 assignee Claimed by @davidfowl View on GitHub
area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] 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](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0#explicit-parameter-binding) shows the following example where `Service` is injected into the delegate and resolved from the configuration system:

``` c#
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 https://github.com/dotnet/aspnetcore/issues/30115, https://github.com/dotnet/aspnetcore/issues/29194, https://github.com/dotnet/aspnetcore/issues/28957, https://github.com/dotnet/aspnetcore/issues/14585, https://github.com/dotnet/aspnetcore/issues/8886 and https://github.com/aspnet/DependencyInjection/issues/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.