-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (47 loc) · 1.97 KB
/
Program.cs
File metadata and controls
60 lines (47 loc) · 1.97 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
using Cleipnir.Flows.AspNet;
using Cleipnir.Flows.HelloWorld.Clients;
using Cleipnir.Flows.PostgresSql;
using Cleipnir.ResilientFunctions.PostgreSQL;
using Serilog;
namespace Cleipnir.Flows.HelloWorld;
internal static class Program
{
private static async Task Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
builder.Services.AddSingleton<IEmailClient, EmailClientStub>();
builder.Services.AddSingleton<ILogisticsClient, LogisticsClientStub>();
builder.Services.AddSingleton<IPaymentProviderClient, PaymentProviderClientStub>();
const string connectionString = "Server=localhost;Port=5432;Userid=postgres;Password=Pa55word!;Database=flows;";
await DatabaseHelper.CreateDatabaseIfNotExists(connectionString); //use to create db initially or clean existing state in database
//await DatabaseHelper.RecreateDatabase(connectionString);
builder.Services.AddFlows(c => c
.UsePostgresStore(connectionString)
.WithOptions(new Options(leaseLength: TimeSpan.FromSeconds(5), messagesDefaultMaxWaitForCompletion: TimeSpan.MaxValue))
.RegisterFlowsAutomatically()
);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("", context =>
{
context.Response.Redirect("/swagger");
return Task.CompletedTask;
});
app.UseAuthorization();
app.MapControllers();
await app.RunAsync();
}
}