dotnet / dotnet/aspnetcore

RequestDelegate is not injected on middlewares using Primary Constructor

Open
#53,490 2 comments 0 reactions 0 assignees View on GitHub
area-middleware
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When using primary constructors, the `RequestDelegate` comes null, causing `404` to be returned everytime. When using default constructors, it is injected just fine, which is expected.

![Imagem do WhatsApp de 2024-01-19 à(s) 14 45 09_64192b56](https://github.com/dotnet/aspnetcore/assets/54086793/4c9035f9-0028-490f-9900-8526017085bf)

### Expected Behavior

Since primary constructor is the same of having a single construtor definition, it should have the same behaviour as injecting the `RequestDelegate` in the default constructor.

### Steps To Reproduce

• Create a middleware
• Use the new primary constructor to inject the RequestDelegate
• Verify during debug that it is injected as null

### Exceptions (if any)

_No response_

### .NET Version

8

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the middleware behavior described in issue #53490 on .NET 8, comparing a primary constructor with a default constructor. Trace how RequestDelegate is supplied during middleware activation and confirm the fix by verifying it is non-null and the middleware no longer returns an unintended 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.