Skip to content

Commit 5ae570d

Browse files
authored
Expose Use as a public method on WAB (#38011)
- Added a test to verify that it is publicly callable
1 parent 004c969 commit 5ae570d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/DefaultBuilder/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Microsoft.AspNetCore.Builder.WebApplication.Services.get -> System.IServiceProvi
2525
Microsoft.AspNetCore.Builder.WebApplication.StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
2626
Microsoft.AspNetCore.Builder.WebApplication.StopAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
2727
Microsoft.AspNetCore.Builder.WebApplication.Urls.get -> System.Collections.Generic.ICollection<string!>!
28+
Microsoft.AspNetCore.Builder.WebApplication.Use(System.Func<Microsoft.AspNetCore.Http.RequestDelegate!, Microsoft.AspNetCore.Http.RequestDelegate!>! middleware) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
2829
Microsoft.AspNetCore.Builder.WebApplicationBuilder
2930
Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build() -> Microsoft.AspNetCore.Builder.WebApplication!
3031
Microsoft.AspNetCore.Builder.WebApplicationBuilder.Configuration.get -> Microsoft.Extensions.Configuration.ConfigurationManager!

src/DefaultBuilder/src/WebApplication.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ IApplicationBuilder IApplicationBuilder.New()
181181
return newBuilder;
182182
}
183183

184-
IApplicationBuilder IApplicationBuilder.Use(Func<RequestDelegate, RequestDelegate> middleware)
184+
/// <summary>
185+
/// Adds the middleware to the application request pipeline.
186+
/// </summary>
187+
/// <param name="middleware">The middleware.</param>
188+
/// <returns>An instance of <see cref="IApplicationBuilder"/> after the operation has completed.</returns>
189+
public IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
185190
{
186191
ApplicationBuilder.Use(middleware);
187192
return this;

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,26 @@ public void ConfigurationProviderTypesArePreserved()
18351835
Assert.Single(((IConfigurationRoot)app.Configuration).Providers.OfType<RandomConfigurationProvider>());
18361836
}
18371837

1838+
[Fact]
1839+
public async Task CanUseMiddleware()
1840+
{
1841+
var builder = WebApplication.CreateBuilder();
1842+
builder.WebHost.UseTestServer();
1843+
await using var app = builder.Build();
1844+
1845+
app.Use(next =>
1846+
{
1847+
return context => context.Response.WriteAsync("Hello World");
1848+
});
1849+
1850+
await app.StartAsync();
1851+
1852+
var client = app.GetTestClient();
1853+
1854+
var response = await client.GetStringAsync("/");
1855+
Assert.Equal("Hello World", response);
1856+
}
1857+
18381858
public class RandomConfigurationSource : IConfigurationSource
18391859
{
18401860
public int ProvidersBuilt { get; set; }

0 commit comments

Comments
 (0)