-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (58 loc) · 2.65 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (58 loc) · 2.65 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
using Cleipnir.Flows.AspNet;
using Cleipnir.Flows.PostgresSql;
using Cleipnir.Flows.Sample.MicrosoftOpen.Clients;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.Batch;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.Invoice;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven.Other;
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.Rpc.Solution;
using Cleipnir.ResilientFunctions.PostgreSQL;
using Serilog;
namespace Cleipnir.Flows.Sample.MicrosoftOpen;
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(replicaHeartbeatFrequency: TimeSpan.FromSeconds(5), messagesDefaultMaxWaitForCompletion: TimeSpan.MaxValue))
.RegisterFlow<OrderFlow, Order>()
.RegisterFlow<BatchOrderFlow, List<Order>>()
.RegisterFlow<SingleOrderFlow, Order, TransactionIdAndTrackAndTrace>()
.RegisterFlow<InvoiceFlow, CustomerNumber>()
.RegisterFlow<MessageDrivenOrderFlow, Order>()
);
builder.Services.AddInMemoryBus();
// 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();
}
}