fix sample (#23990)

pull/23991/head
Rick Anderson 2021-11-19 08:40:17 -10:00 committed by GitHub
parent 69eff41455
commit 915694b3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -249,7 +249,7 @@ Service1.Dispose
Consider the following code:
[!code-csharp[](dependency-injection/samples/6.x/DIsample2/DIsample2/Program.cs?name=snippet2)]
[!code-csharp[](dependency-injection/samples/6.x/DIsample2/DIsample2/Program.cs?name=snippet3)]
In the preceding code:

View File

@ -1,4 +1,4 @@
#define SECOND // FIRST SECOND
#define THRD // FIRST SECOND THRD
#if FIRST
#region snippet
using DIsample2.Services;
@ -61,5 +61,36 @@ app.UseAuthorization();
app.MapRazorPages();
app.Run();
#elif THRD
using DIsample2.Services;
#region snippet3
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddSingleton(new Service1());
builder.Services.AddSingleton(new Service2());
#endregion
var myKey = builder.Configuration["MyKey"];
builder.Services.AddSingleton<IService3>(sp => new Service3(myKey));
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
#endif