-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathProgram.cs
33 lines (28 loc) · 1.03 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma warning disable CS9113 // Parameter is unread.
using Microsoft.AspNetCore.Mvc;
using MinimalWebAPI;
using WeatherForecast;
var composition = new Composition();
var builder = WebApplication.CreateBuilder(args);
// Uses Composition as an alternative IServiceProviderFactory
builder.Host.UseServiceProviderFactory(composition);
var app = builder.Build();
// Creates an application composition root of type `Program`
var compositionRoot = composition.Root;
compositionRoot.Run(app);
partial class Program(
// Dependencies could be injected here
ILogger<Program> logger,
IWeatherForecastService weatherForecast)
{
private void Run(WebApplication app)
{
app.MapGet("/", async (
// Dependencies can be injected here as well
[FromServices] IWeatherForecastService anotherOneWeatherForecast) => {
logger.LogInformation("Start of request execution");
return await anotherOneWeatherForecast.CreateWeatherForecastAsync().ToListAsync();
});
app.Run();
}
}