Fixer/Analyzer: Hoist explicit calls to HttpContext.RequestServices.GetService to route handler parameters
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
We should have a fixer that rewrites calls to GetRequiredService to injecting them directly into handler methods. Code should go from this:
```C#
app.MapGet("/", (HttpContext context) =>
{
var service = context.RequestServices.GetRequiredService();
return service.GetTodos();
});
```
To this:
```C#
app.MapGet("/", (ITodoService service) =>
{
return service.GetTodos();
});
```
Contributor guide
Research direction
No files or tests are named. Start by locating the analyzer and fixer entry points for MapGet route handlers, then use the GetRequiredService example as the reproduction. Done means the explicit service lookup is represented as a handler parameter and existing analyzer/fixer tests cover the transformation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100