This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathProgram.cs
More file actions
99 lines (95 loc) · 3.8 KB
/
Program.cs
File metadata and controls
99 lines (95 loc) · 3.8 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
91
92
93
94
95
96
97
98
99
using System;
using System.Threading.Tasks;
using Convey;
using Convey.CQRS.Commands;
using Convey.CQRS.Events;
using Convey.CQRS.Queries;
using Convey.Discovery.Consul;
using Convey.Docs.Swagger;
using Convey.HTTP;
using Convey.LoadBalancing.Fabio;
using Convey.Logging;
using Convey.MessageBrokers.CQRS;
using Convey.MessageBrokers.Outbox;
using Convey.MessageBrokers.Outbox.Mongo;
using Convey.MessageBrokers.RabbitMQ;
using Convey.Metrics.Prometheus;
using Convey.Persistence.MongoDB;
using Convey.Persistence.Redis;
using Convey.Secrets.Vault;
using Convey.Tracing.Jaeger;
using Convey.Tracing.Jaeger.RabbitMQ;
using Convey.WebApi;
using Convey.WebApi.CQRS;
using Convey.WebApi.Security;
using Convey.WebApi.Swagger;
using Conveyor.Services.Orders.Commands;
using Conveyor.Services.Orders.Domain;
using Conveyor.Services.Orders.DTO;
using Conveyor.Services.Orders.Events.External;
using Conveyor.Services.Orders.Queries;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace Conveyor.Services.Orders;
public class Program
{
public static Task Main(string[] args)
=> CreateHostBuilder(args).Build().RunAsync();
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
{
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddJsonFile("appsettings.json")
.Build();
webBuilder.ConfigureServices(services => services
.AddConvey()
.AddErrorHandler<ExceptionToResponseMapper>()
.AddServices()
.AddHttpClient()
.AddCorrelationContextLogging()
.AddConsul()
.AddFabio()
.AddJaeger()
.AddMongo()
.AddMongoRepository<Order, Guid>("orders")
.AddCommandHandlers()
.AddEventHandlers()
.AddQueryHandlers()
.AddInMemoryCommandDispatcher()
.AddInMemoryEventDispatcher()
.AddInMemoryQueryDispatcher()
.AddPrometheus()
.AddRedis()
.AddRabbitMq(plugins: p => p.AddJaegerRabbitMqPlugin())
.AddMessageOutbox(o => o.AddMongo())
.AddWebApi()
.AddSwaggerDocs()
.AddWebApiSwaggerDocs()
.Build())
.Configure(app => app
.UseConvey()
.UserCorrelationContextLogging()
.UseErrorHandler()
.UsePrometheus()
.UseRouting()
.UseCertificateAuthentication()
.UseEndpoints(r => r.MapControllers())
.UseDispatcherEndpoints(endpoints => endpoints
.Get("", ctx => ctx.Response.WriteAsync("Orders Service"))
.Get("ping", ctx => ctx.Response.WriteAsync("pong"))
.Get<GetOrder, OrderDto>("orders/{orderId}")
.Post<CreateOrder>("orders",
afterDispatch: (cmd, ctx) => ctx.Response.Created($"orders/{cmd.OrderId}")))
.UseJaeger()
.UseSwaggerDocs()
.UseRabbitMq()
.SubscribeEvent<DeliveryStarted>())
.UseLogging()
.UseVault(configuration);
});
}