Skip to content

Commit 7b11171

Browse files
Update StartupUseWhen.cs (docs) for ILogger to work with .NET Core 3+ (#20078)
* Update StartupUseWhen.cs to work with .NET Core 3+ According to dotnet/extensions#1096, in .NET Core 3+ you can no longer resolve ILogger when activating Startup and need to pass ILogger as parameter in Configure method. * Update StartupUseWhen.cs Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
1 parent c7ff12c commit 7b11171

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

aspnetcore/fundamentals/middleware/index/snapshot/Chain/StartupUseWhen.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
public class Startup
1+
public class Startup
22
{
3-
private readonly ILogger<Startup> _logger;
4-
5-
public Startup(ILogger<Startup> logger)
6-
{
7-
_logger = logger;
8-
}
9-
10-
private void HandleBranchAndRejoin(IApplicationBuilder app)
3+
private void HandleBranchAndRejoin(IApplicationBuilder app, ILogger<Startup> logger)
114
{
125
app.Use(async (context, next) =>
136
{
147
var branchVer = context.Request.Query["branch"];
15-
_logger.LogInformation("Branch used = {branchVer}", branchVer);
8+
logger.LogInformation("Branch used = {branchVer}", branchVer);
169

1710
// Do work that doesn't write to the Response.
1811
await next();
1912
// Do other work that doesn't write to the Response.
2013
});
2114
}
2215

23-
public void Configure(IApplicationBuilder app)
16+
public void Configure(IApplicationBuilder app, ILogger<Startup> logger)
2417
{
2518
app.UseWhen(context => context.Request.Query.ContainsKey("branch"),
26-
HandleBranchAndRejoin);
19+
appBuilder => HandleBranchAndRejoin(appBuilder, logger));
2720

2821
app.Run(async context =>
2922
{

0 commit comments

Comments
 (0)