-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
90 lines (71 loc) · 2.7 KB
/
Copy pathProgram.cs
File metadata and controls
90 lines (71 loc) · 2.7 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using FluentValidation;
using SmartMovieCatalog.Api.Common;
using SmartMovieCatalog.Api.Features.Auth;
using SmartMovieCatalog.Api.Features.Auth.Authenticate;
using SmartMovieCatalog.Api.Features.Movies;
using SmartMovieCatalog.Api.Features.Movies.CreateMovie;
using SmartMovieCatalog.Application;
using SmartMovieCatalog.Contracts.Auth;
using SmartMovieCatalog.Contracts.Movies;
using SmartMovieCatalog.Infrastructure;
using SmartMovieCatalog.Infrastructure.Persistence;
using Wolverine;
namespace SmartMovieCatalog.Api
{
public class Program
{
protected Program()
{
}
public static int Main(string[] args)
{
if (args is ["--healthcheck"])
{
return HealthCheckRunner.Run();
}
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddApplication();
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddScoped<IValidator<AuthenticateRequest>, AuthenticateRequestValidator>();
builder.Services.AddScoped<IValidator<CreateMovieRequest>, CreateMovieRequestValidator>();
builder.Services.AddHealthChecks();
builder.Services.AddOpenApi();
builder.AddAuthConfiguration();
builder.Host.UseWolverine(options =>
{
options.EnableRemoteInvocation = false;
options.Discovery.IncludeAssembly(ApplicationReference.Assembly);
});
var app = builder.Build();
if (!app.Environment.IsEnvironment("Testing"))
{
using IServiceScope scope = app.Services.CreateScope();
DatabaseBootstrapper databaseBootstrapper = scope.ServiceProvider.GetRequiredService<DatabaseBootstrapper>();
databaseBootstrapper.BootstrapAsync(CancellationToken.None).GetAwaiter().GetResult();
}
if (!app.Environment.IsEnvironment("Testing"))
{
app.UseDefaultFiles();
app.MapStaticAssets();
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapAuthEndpoints();
app.MapMovieEndpoints();
app.MapHealthChecks("/health");
if (!app.Environment.IsEnvironment("Testing"))
{
app.MapFallbackToFile("/index.html");
}
app.Run();
return 0;
}
}
}