KevinDockx / HttpCacheHeaders

ASP.NET Core middleware that adds HttpCache headers to responses (Cache-Control, Expires, ETag, Last-Modified), and implements cache expiration & validation models
MIT License
271 stars 57 forks source link

Check whether the call into UseHttpCacheHeaders is situated between UseRouting and UseEndpoints #101

Closed KevinDockx closed 3 years ago

KevinDockx commented 3 years ago

Check whether the call into UseHttpCacheHeaders is situated between UseRouting and UseEndpoints - allows for throwing a nice Exception to inform users of this.

Cfr: https://github.com/dotnet/aspnetcore/blob/main/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs#L135

KevinDockx commented 3 years ago

RoutingMarkerService is internal - cannot use this to check. Consider ASP.NET Core feature request.

https://github.com/dotnet/aspnetcore/blob/main/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs#L122

KevinDockx commented 3 years ago

Feature request: https://github.com/dotnet/aspnetcore/issues/37679

KevinDockx commented 3 years ago

As per Javier's answer on the feature request: for now, use the alternative and check if we can resolve a publicly exposed type, like EndpointDataSource.

In the future, consider an analyzer.

KevinDockx commented 3 years ago

https://github.com/KevinDockx/HttpCacheHeaders/issues/102

KevinDockx commented 3 years ago

Answer isn't sufficient: checking the registered type only checks whether a service is registered on a container, NOT the order in which middleware is added to the request pipeline...