MVC1004 should not warn for [FromServices] parameters
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
MVC1004 is warning for parameters that are injected from services.
### Expected Behavior
MVC1004 does not warn for any BindingSource that is `isFromRequest: false`, or at least not `BindingSource.Services`.
It should probably also not warn for getter-only properties that will never be bound.
### Steps To Reproduce
```c#
public class HomeController : Controller
{
[HttpGet]
public async Task Get([FromServices] SiteSettingsService settings) { /* stuff */ }
^^^^^^^^ MVC1004
}
public class SiteSettings { }
public class SiteSettingsService(AppDbContext db)
{
private SiteSettings _settings;
public SiteSettings Settings => _settings ??= db.SiteSettings.First();
// ... other unrelated stuff
}
```
### Exceptions (if any)
_No response_
### .NET Version
10.0.100-rc.1.25451.107
### Anything else?
Tried TargetFramework both net8.0 and net10.0 (10.0.100-rc.1.25451.107)
Contributor guide
Assessment
This issue has not been assessed yet.