|
| 1 | +using System.Text.Json.Serialization; |
| 2 | +using Blumchen.Configuration; |
| 3 | +using Blumchen.Serialization; |
| 4 | +using Blumchen.Subscriptions; |
| 5 | +using Blumchen.Workers; |
| 6 | +using Commons; |
| 7 | +using Microsoft.Extensions.DependencyInjection; |
| 8 | +using Microsoft.Extensions.Hosting; |
| 9 | +using Microsoft.Extensions.Logging; |
| 10 | +using Polly.Retry; |
| 11 | +using Polly; |
| 12 | +using SubscriberWorker; |
| 13 | + |
| 14 | + |
| 15 | +#pragma warning disable CS8601 // Possible null reference assignment. |
| 16 | +Console.Title = typeof(Program).Assembly.GetName().Name; |
| 17 | +#pragma warning restore CS8601 // Possible null reference assignment. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +AppDomain.CurrentDomain.UnhandledException += (_, e) => Console.Out.WriteLine(e.ExceptionObject.ToString()); |
| 22 | +TaskScheduler.UnobservedTaskException += (_, e) => Console.Out.WriteLine(e.Exception.ToString()); |
| 23 | + |
| 24 | +var cancellationTokenSource = new CancellationTokenSource(); |
| 25 | +var builder = Host.CreateApplicationBuilder(args); |
| 26 | + |
| 27 | +builder.Services |
| 28 | + .AddBlumchen<SubscriberWorker<UserCreatedContract>, UserCreatedContract>() |
| 29 | + .AddSingleton<IHandler<UserCreatedContract>, Handler<UserCreatedContract>>() |
| 30 | + .AddBlumchen<SubscriberWorker<UserDeletedContract>, UserDeletedContract>() |
| 31 | + .AddSingleton<IHandler<UserDeletedContract>, Handler<UserDeletedContract>>() |
| 32 | + |
| 33 | + .AddSingleton<INamingPolicy, AttributeNamingPolicy>() |
| 34 | + .AddSingleton<IErrorProcessor, ConsoleOutErrorProcessor>() |
| 35 | + .AddSingleton<JsonSerializerContext, SourceGenerationContext>() |
| 36 | + .AddSingleton(new DatabaseOptions(Settings.ConnectionString)) |
| 37 | + .AddResiliencePipeline("default",(pipelineBuilder,context) => |
| 38 | + pipelineBuilder |
| 39 | + .AddRetry(new RetryStrategyOptions |
| 40 | + { |
| 41 | + BackoffType = DelayBackoffType.Constant, |
| 42 | + Delay = TimeSpan.FromSeconds(5), |
| 43 | + MaxRetryAttempts = int.MaxValue |
| 44 | + }).Build()) |
| 45 | + .AddLogging(loggingBuilder => |
| 46 | + { |
| 47 | + loggingBuilder |
| 48 | + .AddFilter("Microsoft", LogLevel.Warning) |
| 49 | + .AddFilter("System", LogLevel.Warning) |
| 50 | + .AddFilter("Npgsql", LogLevel.Information) |
| 51 | + .AddFilter("Blumchen", LogLevel.Debug) |
| 52 | + .AddFilter("SubscriberWorker", LogLevel.Debug) |
| 53 | + .AddSimpleConsole(); |
| 54 | + }); |
| 55 | + |
| 56 | +await builder |
| 57 | + .Build() |
| 58 | + .RunAsync(cancellationTokenSource.Token) |
| 59 | + .ConfigureAwait(false); |
0 commit comments