From fe650c4dea9d32ff2b742519ca46805c095780c1 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Fri, 5 Apr 2024 09:30:30 +0100 Subject: [PATCH 1/3] upgrade event store registrations --- .../Bootstrapper/MiddlewareRegistry.cs | 15 +++++++---- .../Bootstrapper/RepositoryRegistry.cs | 27 +++---------------- CallbackHandler/Startup.cs | 13 --------- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs index fa1ca57..79aaee9 100644 --- a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs +++ b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs @@ -5,7 +5,9 @@ using System.IO; using System.Reflection; using Common; + using EventStore.Client; using Lamar; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.OpenApi.Models; @@ -19,11 +21,14 @@ public class MiddlewareRegistry :ServiceRegistry { public MiddlewareRegistry() { - this.AddHealthChecks().AddEventStore(Startup.EventStoreClientSettings, - userCredentials: Startup.EventStoreClientSettings.DefaultCredentials, - name: "Eventstore", - failureStatus: HealthStatus.Unhealthy, - tags: new string[] { "db", "eventstore" }); + String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); + EventStoreClientSettings eventStoreSettings = EventStoreClientSettings.Create(connectionString); + + this.AddHealthChecks().AddEventStore(eventStoreSettings, + userCredentials: eventStoreSettings.DefaultCredentials, + name: "Eventstore", + failureStatus: HealthStatus.Unhealthy, + tags: new string[] { "db", "eventstore" }); this.AddSwaggerGen(c => { diff --git a/CallbackHandler/Bootstrapper/RepositoryRegistry.cs b/CallbackHandler/Bootstrapper/RepositoryRegistry.cs index d7dd7a3..f07a93e 100644 --- a/CallbackHandler/Bootstrapper/RepositoryRegistry.cs +++ b/CallbackHandler/Bootstrapper/RepositoryRegistry.cs @@ -21,31 +21,12 @@ public RepositoryRegistry() { this.AddTransient(); this.AddSingleton, AggregateRepository>(); - - Boolean insecureES = Startup.Configuration.GetValue("EventStoreSettings:Insecure"); - Func CreateHttpMessageHandler = () => new SocketsHttpHandler - { - SslOptions = new SslClientAuthenticationOptions - { - RemoteCertificateValidationCallback = (sender, - certificate, - chain, - errors) => { - return true; - } - } - }; + String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); - this.AddEventStoreProjectionManagementClient(Startup.ConfigureEventStoreSettings); + this.AddEventStoreProjectionManagementClient(connectionString); + this.AddEventStorePersistentSubscriptionsClient(connectionString); - if (insecureES) - { - this.AddInSecureEventStoreClient(Startup.EventStoreClientSettings.ConnectivitySettings.Address, CreateHttpMessageHandler); - } - else - { - this.AddEventStoreClient(Startup.EventStoreClientSettings.ConnectivitySettings.Address, CreateHttpMessageHandler); - } + this.AddEventStoreClient(connectionString); } } \ No newline at end of file diff --git a/CallbackHandler/Startup.cs b/CallbackHandler/Startup.cs index 0d3020e..811e784 100644 --- a/CallbackHandler/Startup.cs +++ b/CallbackHandler/Startup.cs @@ -72,19 +72,6 @@ public Startup(IWebHostEnvironment webHostEnvironment) /// public static IWebHostEnvironment WebHostEnvironment { get; set; } - internal static EventStoreClientSettings EventStoreClientSettings; - - internal static void ConfigureEventStoreSettings(EventStoreClientSettings settings) - { - settings.ConnectivitySettings = EventStoreClientConnectivitySettings.Default; - settings.ConnectivitySettings.Address = new Uri(Startup.Configuration.GetValue("EventStoreSettings:ConnectionString")); - settings.ConnectivitySettings.Insecure = Startup.Configuration.GetValue("EventStoreSettings:Insecure"); - - settings.DefaultCredentials = new UserCredentials(Startup.Configuration.GetValue("EventStoreSettings:UserName"), - Startup.Configuration.GetValue("EventStoreSettings:Password")); - Startup.EventStoreClientSettings = settings; - } - public static Container Container; // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) From c535626e34ca74764ede77fa6769085b43bc3990 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Fri, 5 Apr 2024 10:24:41 +0100 Subject: [PATCH 2/3] :| --- CallbackHandler/Bootstrapper/MiddlewareRegistry.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs index 79aaee9..5e3ed2a 100644 --- a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs +++ b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs @@ -48,8 +48,8 @@ public MiddlewareRegistry() c.ExampleFilters(); //Locate the XML files being generated by ASP.NET... - var directory = new DirectoryInfo(AppContext.BaseDirectory); - var xmlFiles = directory.GetFiles("*.xml"); + DirectoryInfo directory = new DirectoryInfo(AppContext.BaseDirectory); + FileInfo[] xmlFiles = directory.GetFiles("*.xml"); //... and tell Swagger to use those XML comments. foreach (FileInfo fileInfo in xmlFiles) From 344a40218860c8fcbf0d1dc09bd8f19d751c14b1 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Fri, 5 Apr 2024 10:29:33 +0100 Subject: [PATCH 3/3] fix tests --- CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs | 2 +- CallbackHandler.Tests/BootstrapperTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs b/CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs index a6ca824..51c1fa6 100644 --- a/CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs +++ b/CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs @@ -72,7 +72,7 @@ private IConfigurationRoot SetupMemoryConfiguration() configuration.Add("ConnectionStrings:HealthCheck", "HeathCheckConnString"); configuration.Add("SecurityConfiguration:Authority", "https://127.0.0.1"); - configuration.Add("EventStoreSettings:ConnectionString", "https://127.0.0.1:2113"); + configuration.Add("EventStoreSettings:ConnectionString", "esdb://127.0.0.1:2113"); configuration.Add("EventStoreSettings:ConnectionName", "UnitTestConnection"); configuration.Add("EventStoreSettings:UserName", "admin"); configuration.Add("EventStoreSettings:Password", "changeit"); diff --git a/CallbackHandler.Tests/BootstrapperTests.cs b/CallbackHandler.Tests/BootstrapperTests.cs index 7f6c3c1..3da2ea2 100644 --- a/CallbackHandler.Tests/BootstrapperTests.cs +++ b/CallbackHandler.Tests/BootstrapperTests.cs @@ -40,7 +40,7 @@ private IConfigurationRoot SetupMemoryConfiguration() configuration.Add("ConnectionStrings:HealthCheck", "HeathCheckConnString"); configuration.Add("SecurityConfiguration:Authority", "https://127.0.0.1"); - configuration.Add("EventStoreSettings:ConnectionString", "https://127.0.0.1:2113"); + configuration.Add("EventStoreSettings:ConnectionString", "esdb://127.0.0.1:2113"); configuration.Add("EventStoreSettings:ConnectionName", "UnitTestConnection"); configuration.Add("EventStoreSettings:UserName", "admin"); configuration.Add("EventStoreSettings:Password", "changeit");