Skip to content

Commit d3a8677

Browse files
Update ES registrations
1 parent 0ae7021 commit d3a8677

File tree

4 files changed

+15
-59
lines changed

4 files changed

+15
-59
lines changed

MessagingService/Bootstrapper/MiddlewareRegistry.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@
1616
using Microsoft.OpenApi.Models;
1717
using Newtonsoft.Json;
1818
using Newtonsoft.Json.Serialization;
19-
using Shared.EventStore.EventStore;
2019
using Shared.EventStore.Extensions;
2120
using Shared.General;
2221
using Swashbuckle.AspNetCore.Filters;
2322
using System.Collections.Generic;
2423
using System.Linq;
2524
using System.Diagnostics.CodeAnalysis;
25+
using Microsoft.Extensions.Configuration;
2626

2727
[ExcludeFromCodeCoverage]
2828
public class MiddlewareRegistry : ServiceRegistry
2929
{
3030
public MiddlewareRegistry() {
31+
32+
String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
33+
EventStoreClientSettings eventStoreConnectionSettings = EventStoreClientSettings.Create(connectionString);
34+
3135
this.AddHealthChecks()
32-
.AddEventStore(Startup.EventStoreClientSettings,
36+
.AddEventStore(eventStoreConnectionSettings,
3337
name: "Eventstore",
3438
failureStatus: HealthStatus.Unhealthy,
3539
tags: new string[] { "db", "eventstore" });

MessagingService/Bootstrapper/RepositoryRegistry.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,12 @@ public RepositoryRegistry()
3939
}
4040
else
4141
{
42-
Boolean insecureES = Startup.Configuration.GetValue<Boolean>("EventStoreSettings:Insecure");
42+
String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
4343

44-
Func<SocketsHttpHandler> CreateHttpMessageHandler = () => new SocketsHttpHandler
45-
{
46-
SslOptions = new SslClientAuthenticationOptions
47-
{
48-
RemoteCertificateValidationCallback = (sender,
49-
certificate,
50-
chain,
51-
errors) => {
52-
return true;
53-
}
54-
}
55-
};
44+
this.AddEventStoreProjectionManagementClient(connectionString);
45+
this.AddEventStorePersistentSubscriptionsClient(connectionString);
5646

57-
this.AddEventStoreProjectionManagementClient(Startup.ConfigureEventStoreSettings);
58-
this.AddEventStorePersistentSubscriptionsClient(Startup.ConfigureEventStoreSettings);
59-
60-
if (insecureES)
61-
{
62-
this.AddInSecureEventStoreClient(Startup.EventStoreClientSettings.ConnectivitySettings.Address, CreateHttpMessageHandler);
63-
}
64-
else
65-
{
66-
this.AddEventStoreClient(Startup.EventStoreClientSettings.ConnectivitySettings.Address, CreateHttpMessageHandler);
67-
}
47+
this.AddEventStoreClient(connectionString);
6848

6949
this.AddSingleton<IConnectionStringConfigurationRepository, ConfigurationReaderConnectionStringRepository>();
7050
}

MessagingService/Common/Extensions.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919
[ExcludeFromCodeCoverage]
2020
public static class Extensions
2121
{
22-
public static IServiceCollection AddInSecureEventStoreClient(
23-
this IServiceCollection services,
24-
Uri address,
25-
Func<HttpMessageHandler>? createHttpMessageHandler = null)
26-
{
27-
return services.AddEventStoreClient((Action<EventStoreClientSettings>)(options =>
28-
{
29-
options.ConnectivitySettings.Address = address;
30-
options.ConnectivitySettings.Insecure = true;
31-
options.CreateHttpMessageHandler = createHttpMessageHandler;
32-
}));
33-
}
34-
3522
static Action<TraceEventType, String, String> log = (tt,
3623
subType,
3724
message) => {
@@ -74,9 +61,12 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder)
7461

7562
Func<String, Int32, ISubscriptionRepository> subscriptionRepositoryResolver = Startup.Container.GetInstance<Func<String, Int32, ISubscriptionRepository>>();
7663

64+
65+
String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
66+
EventStoreClientSettings eventStoreConnectionSettings = EventStoreClientSettings.Create(connectionString);
7767
applicationBuilder.ConfigureSubscriptionService(subscriptionWorkersRoot,
7868
eventStoreConnectionString,
79-
Startup.EventStoreClientSettings,
69+
eventStoreConnectionSettings,
8070
eventHandlerResolvers,
8171
Extensions.log,
8272
subscriptionRepositoryResolver,

MessagingService/Startup.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,12 @@ public Startup(IWebHostEnvironment webHostEnvironment)
4848
public static IConfigurationRoot Configuration { get; set; }
4949

5050
public static IWebHostEnvironment WebHostEnvironment { get; set; }
51-
52-
internal static EventStoreClientSettings EventStoreClientSettings;
53-
51+
5452
public static void LoadTypes()
5553
{
56-
RequestSentToEmailProviderEvent e = new RequestSentToEmailProviderEvent(Guid.Parse("2AA2D43B-5E24-4327-8029-1135B20F35CE"), "", new List<String>(),
57-
"", "", true);
58-
59-
RequestSentToSMSProviderEvent s = new RequestSentToSMSProviderEvent(Guid.NewGuid(), "", "", "");
60-
6154
TypeProvider.LoadDomainEventsTypeDynamically();
6255
}
6356

64-
public static void ConfigureEventStoreSettings(EventStoreClientSettings settings)
65-
{
66-
String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
67-
68-
Startup.EventStoreClientSettings = EventStoreClientSettings.Create(connectionString); ;
69-
}
70-
7157
public static Container Container;
7258

7359
public void ConfigureContainer(ServiceRegistry services)
@@ -82,11 +68,7 @@ public void ConfigureContainer(ServiceRegistry services)
8268
services.IncludeRegistry<MessagingProxyRegistry>();
8369

8470
Startup.Container = new Container(services);
85-
86-
//Startup.ServiceProvider = services.BuildServiceProvider();
8771
}
88-
89-
//public static IServiceProvider ServiceProvider { get; set; }
9072

9173
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
9274
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)

0 commit comments

Comments
 (0)