API Review: Make IAcceptsMetadata and IProducesResponseTypeMetadata public.
See original GitHub issueBackground and Motivation
During the development of the Request Delegate Generator we inject an implementation of the Microsoft.AspNetCore.Http.Metadata.IAcceptsMetadata
and Microsoft.AspNetCore.HttpMetadata.IProducesResponseTypeMetadata
interfaces.
For non-generated scenarios there is a single implementation of these interfaces that we share via source between all the libraries that require them (src/Shared/RoutingMetadata/AcceptsMetadata.cs
and src/Shared/ApiExplorerTypes/ProducesResponseTypeMetadata.cs
respectively).
The proposal is that we centralize these types in the Microsoft.AspNetCore.Http.Abstractions
assembly. We would use the existing shared soruce internal implementation.
Proposed API
namespace Microsoft.AspNetCore.Http.Metadata
+ public sealed class ProducesResponseTypeMetadata : IProducesResponseTypeMetadata
{
+ public ProducesResponseTypeMetadata(int statusCode)
+ public ProducesResponseTypeMetadata(Type type, int statusCode)
+ public ProducesResponseTypeMetadata(Type type, int statusCode, string contentType, params string[] additionalContentTypes)
+ public Type? Type { get; set; }
+ public int StatusCode { get; set; }
+ public IEnumerable<string> ContentTypes => _contentTypes;
}
public sealed class AcceptsMetadata : IAcceptsMetadata
{
+ public AcceptsMetadata(string[] contentTypes)
+ public AcceptsMetadata(Type? type, bool isOptional, string[] contentTypes)
+ public IReadOnlyList<string> ContentTypes { get; }
+ public Type? RequestType { get; }
+ public bool IsOptional { get; }
}
We may wish to expose a type with content values used in the constructor of these types (e.g. application/json
).
Usage Examples
Usage if this type already exists in the framework today because it is shared source:
All of these usages would be updated to use the new public type.
Alternative Designs
Because this came up during the development of the source generator we could try to publish a “support assembly” for types that we need in the source generator. This support assembly would contain public concrete implementations for interfaces like IAcceptsMetadata
. The idea would be that these types don’t have the same API compatibility guarantees as the rest of the framework since they are designed to work alongside the matching source generator.
Risks
By not exposing an implementation of IAcceptsMetadata
and IProducesResponseTypeMetadata
we currently force developers to use the interface if they want to inspect the metadata. We want them to continue during this - however if we make the types public they might start using the concrete types. Although perhaps this is desirable in cases when they want to mutate the metadata on an endpoint themselves.
Unfortunately we can’t use IVT in this scenario because we need to be able to access the types in the generated source.
Issue Analytics
- State:
- Created 5 months ago
- Comments:7 (7 by maintainers)
API Review Notes:
IAcceptsMetadata
is already implemented by MVCsConsumesAttribute
. Do we need another attribute?IResourceFilter
which makes something like type forwarding impractical.ProducesAttribute
does not implementIProducesResponseTypeMetadata
.[FromBody]
,[FromService]
,[FromRoute]
, etc…?API Approved!
PR is up for this. Ended up touching a fair amount of surface area.