-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
60 lines (49 loc) · 2.04 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
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
using aws_service.BackgroundServices;
using aws_service.Database;
using aws_service.Services;
using Microsoft.EntityFrameworkCore;
using Quartz;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add Services to IOC
builder.Services.AddTransient<ISSLService, SSLService>();
builder.Services.AddTransient<IInstanceService, InstanceService>();
builder.Services.AddTransient<IHostedZoneService, HostedZoneService>();
builder.Services.AddTransient<ILoadBalancerService, LoadBalancerService>();
builder.Services.AddTransient<IDomainRecordService, DomainRecordService>();
builder.Services.AddTransient<IOperationCrudService, OperationCrudService>();
builder.Services.AddTransient<IDomainRegistrationService, DomainRegistrationService>();
builder.Services.AddTransient<IDomainAvailabilityService, DomainAvailabilityService>();
builder.Services.AddTransient<IEC2Service, EC2Service>();
// Add Controllers Endpoints
builder.Services.AddControllers()
.AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
// Add Swagger Documentation
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Required by EFCore
builder.Services.AddHttpContextAccessor();
// Register ApplicationDbContext with InMemory Database
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseInMemoryDatabase("db"));
// Register Background Hosted Services
builder.Services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
var jobKey = new JobKey("Operation");
q.AddJob<OperationService>(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("operation-trigger")
.WithCronSchedule("0/5 * * ? * * *"));
});
builder.Services.AddQuartzHostedService();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();