dotnet / dotnet/aspnetcore

FromServicesAttribute isn't considered for inheritance when applied to a property

Open
#68,793 1 comment 0 reactions 1 assignee Claimed by @snemeckayova View on GitHub
area-minimal feature-rdf feature-rdg
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

Use the type `Derived` as `[AsParameters]` in minimal API endpoint.

```csharp
public class C
{
[FromServices]
public virtual MyService Service { get; init; } = null!;
}

public class Derived : C
{
public override MyService Service { get; init; } = null!;
}
```

The FromServicesAttribute is marked as Inherited = true, but not considered for inheritance in this case.

See https://github.com/dotnet/runtime/issues/30219 for why this is happening. We should fix that.

### Expected Behavior

Inheritance is considered. This should be tested for both RDF and RDG. We should also ensure that ApiExplorer and OpenApi match the runtime behavior.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

_No response_

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.