Skip to content

Commit 8373bef

Browse files
authored
Fix Dependency Injection Snippet (#35342)
Fixes the output to console to contain the correct type of service fetched from host, i.e. ServiceLifetimeReporter not ServiceLifetimeLogger.
1 parent 2995a41 commit 8373bef

File tree

1 file changed

+6
-6
lines changed
  • docs/core/extensions/snippets/configuration/console-di

1 file changed

+6
-6
lines changed

docs/core/extensions/snippets/configuration/console-di/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,36 @@ static void ExemplifyServiceLifetime(IServiceProvider hostProvider, string lifet
2424
IServiceProvider provider = serviceScope.ServiceProvider;
2525
ServiceLifetimeReporter logger = provider.GetRequiredService<ServiceLifetimeReporter>();
2626
logger.ReportServiceLifetimeDetails(
27-
$"{lifetime}: Call 1 to provider.GetRequiredService<ServiceLifetimeLogger>()");
27+
$"{lifetime}: Call 1 to provider.GetRequiredService<ServiceLifetimeReporter>()");
2828

2929
Console.WriteLine("...");
3030

3131
logger = provider.GetRequiredService<ServiceLifetimeReporter>();
3232
logger.ReportServiceLifetimeDetails(
33-
$"{lifetime}: Call 2 to provider.GetRequiredService<ServiceLifetimeLogger>()");
33+
$"{lifetime}: Call 2 to provider.GetRequiredService<ServiceLifetimeReporter>()");
3434

3535
Console.WriteLine();
3636
}
3737
// </Program>
3838

3939
// <Output>
4040
// Sample output:
41-
// Lifetime 1: Call 1 to provider.GetRequiredService<ServiceLifetimeLogger>()
41+
// Lifetime 1: Call 1 to provider.GetRequiredService<ServiceLifetimeReporter>()
4242
// IExampleTransientService: d08a27fa-87d2-4a06-98d7-2773af886125 (Always different)
4343
// IExampleScopedService: 402c83c9-b4ed-4be1-b78c-86be1b1d908d (Changes only with lifetime)
4444
// IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same)
4545
// ...
46-
// Lifetime 1: Call 2 to provider.GetRequiredService<ServiceLifetimeLogger>()
46+
// Lifetime 1: Call 2 to provider.GetRequiredService<ServiceLifetimeReporter>()
4747
// IExampleTransientService: b43d68fb-2c7b-4a9b-8f02-fc507c164326 (Always different)
4848
// IExampleScopedService: 402c83c9-b4ed-4be1-b78c-86be1b1d908d (Changes only with lifetime)
4949
// IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same)
5050
//
51-
// Lifetime 2: Call 1 to provider.GetRequiredService<ServiceLifetimeLogger>()
51+
// Lifetime 2: Call 1 to provider.GetRequiredService<ServiceLifetimeReporter>()
5252
// IExampleTransientService: f3856b59-ab3f-4bbd-876f-7bab0013d392 (Always different)
5353
// IExampleScopedService: bba80089-1157-4041-936d-e96d81dd9d1c (Changes only with lifetime)
5454
// IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same)
5555
// ...
56-
// Lifetime 2: Call 2 to provider.GetRequiredService<ServiceLifetimeLogger>()
56+
// Lifetime 2: Call 2 to provider.GetRequiredService<ServiceLifetimeReporter>()
5757
// IExampleTransientService: a8015c6a-08cd-4799-9ec3-2f2af9cbbfd2 (Always different)
5858
// IExampleScopedService: bba80089-1157-4041-936d-e96d81dd9d1c (Changes only with lifetime)
5959
// IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same)

0 commit comments

Comments
 (0)