Skip to content

Call AddMetrics inside AddRouting #50168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static IServiceCollection AddRoutingCore(this IServiceCollection services
{
ArgumentNullException.ThrowIfNull(services);

// Required for IMeterFactory dependency.
services.AddMetrics();

services.TryAddTransient<IInlineConstraintResolver, DefaultInlineConstraintResolver>();
services.TryAddTransient<ObjectPoolProvider, DefaultObjectPoolProvider>();
services.TryAddSingleton<ObjectPool<UriBuildingContext>>(s =>
Expand Down
1 change: 1 addition & 0 deletions src/Http/Routing/src/Microsoft.AspNetCore.Routing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Reference Include="Microsoft.AspNetCore.Http.Features" />
<Reference Include="Microsoft.AspNetCore.Http.Abstractions" />
<Reference Include="Microsoft.AspNetCore.Routing.Abstractions" />
<Reference Include="Microsoft.Extensions.Diagnostics" />
<Reference Include="Microsoft.Extensions.Features" />
<Reference Include="Microsoft.Extensions.ObjectPool" />
<Reference Include="Microsoft.Extensions.Options" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Routing.Matching;
using Microsoft.AspNetCore.Routing.TestObjects;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Testing;
Expand Down Expand Up @@ -393,6 +394,36 @@ public async Task Endpoint_HasBodySizeFeature_SetUsingSizeLimitMetadata(bool isR
Assert.Equal(expectedRequestSizeLimit, actualRequestSizeLimit);
}

[Fact]
public async Task Create_WithoutHostBuilder_Success()
{
// Arrange
var httpContext = CreateHttpContext();

var services = new ServiceCollection();
services.AddLogging();
services.AddOptions();
services.AddSingleton<DiagnosticListener>(s => new DiagnosticListener("Test"));
Copy link
Member Author

@JamesNK JamesNK Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros UseRouting requires DiagnosticListener in DI, but I don't see that in OC source code. I'm confused how it worked before.

services.AddRouting();

var applicationBuilder = new ApplicationBuilder(services.BuildServiceProvider());

applicationBuilder.UseRouting();
applicationBuilder.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", (HttpContext c) => Task.CompletedTask);
});

var requestDelegate = applicationBuilder.Build();

// Act
await requestDelegate(httpContext);

// Assert
var endpointFeature = httpContext.Features.Get<IEndpointFeature>();
Assert.NotNull(endpointFeature);
}

private class RequestSizeLimitMetadata(long? maxRequestBodySize) : IRequestSizeLimitMetadata
{

Expand Down