fix sample (#23990)
parent
69eff41455
commit
915694b3fe
|
@ -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:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue