Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TransactionProcessor.Tests/General/BootstrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private IConfigurationRoot SetupMemoryConfiguration()
configuration.Add("AppSettings:ClientSecret", "clientSecret");
configuration.Add("AppSettings:EstateManagementApi", "http://localhost");
configuration.Add("AppSettings:SecurityService", "http://localhost");
configuration.Add("SecurityConfiguration:Authority", "http://localhost");

builder.AddInMemoryCollection(configuration);

Expand Down
119 changes: 60 additions & 59 deletions TransactionProcessor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ namespace TransactionProcessor
using Common;
using EstateManagement.Client;
using EventStore.Client;
using HealthChecks.UI.Client;
using MediatR;
using MessagingService.BusinessLogic.EventHandling;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Logging;
using Models;
Expand Down Expand Up @@ -69,6 +72,10 @@ public Startup(IWebHostEnvironment webHostEnvironment)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
ConfigurationReader.Initialise(Startup.Configuration);

Startup.ConfigureEventStoreSettings();

this.ConfigureMiddlewareServices(services);

services.AddTransient<IMediator, Mediator>();
Expand Down Expand Up @@ -107,51 +114,8 @@ public void ConfigureServices(IServiceCollection services)
}
else
{
services.AddEventStoreClient((settings) =>
{
settings.CreateHttpMessageHandler = () => new SocketsHttpHandler
{
SslOptions =
{
RemoteCertificateValidationCallback = (sender,
certificate,
chain,
errors) => true,
}
};
settings.ConnectionName = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionName");
settings.ConnectivitySettings = new EventStoreClientConnectivitySettings
{
Address =
new Uri(Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString")),
};
settings.DefaultCredentials = new UserCredentials(Startup.Configuration.GetValue<String>("EventStoreSettings:UserName"),
Startup.Configuration.GetValue<String>("EventStoreSettings:Password"));
});



services.AddEventStoreProjectionManagerClient((settings) =>
{
settings.CreateHttpMessageHandler = () => new SocketsHttpHandler
{
SslOptions =
{
RemoteCertificateValidationCallback = (sender,
certificate,
chain,
errors) => true,
}
};
settings.ConnectionName = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionName");
settings.ConnectivitySettings = new EventStoreClientConnectivitySettings
{
Address =
new Uri(Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString"))
};
settings.DefaultCredentials = new UserCredentials(Startup.Configuration.GetValue<String>("EventStoreSettings:UserName"),
Startup.Configuration.GetValue<String>("EventStoreSettings:Password"));
});
services.AddEventStoreClient(Startup.ConfigureEventStoreSettings);
services.AddEventStoreProjectionManagerClient(Startup.ConfigureEventStoreSettings);
}

services.AddTransient<IEventStoreContext, EventStoreContext>();
Expand Down Expand Up @@ -206,10 +170,55 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IFeeCalculationManager, FeeCalculationManager>();
}


private static EventStoreClientSettings EventStoreClientSettings;

private static void ConfigureEventStoreSettings(EventStoreClientSettings settings = null)
{
if (settings == null)
{
settings = new EventStoreClientSettings();
}

settings.CreateHttpMessageHandler = () => new SocketsHttpHandler
{
SslOptions =
{
RemoteCertificateValidationCallback = (sender,
certificate,
chain,
errors) => true,
}
};
settings.ConnectionName = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionName");
settings.ConnectivitySettings = new EventStoreClientConnectivitySettings
{
Address = new Uri(Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString")),
};

settings.DefaultCredentials = new UserCredentials(Startup.Configuration.GetValue<String>("EventStoreSettings:UserName"),
Startup.Configuration.GetValue<String>("EventStoreSettings:Password"));
Startup.EventStoreClientSettings = settings;
}

private void ConfigureMiddlewareServices(IServiceCollection services)
{
services.AddHealthChecks()
.AddEventStore(Startup.EventStoreClientSettings,
userCredentials: Startup.EventStoreClientSettings.DefaultCredentials,
name: "Eventstore",
failureStatus: HealthStatus.Unhealthy,
tags: new string[] { "db", "eventstore" })
.AddUrlGroup(new Uri($"{ConfigurationReader.GetValue("SecurityConfiguration", "Authority")}/.well-known/openid-configuration"),
name: "Security Service",
httpMethod: HttpMethod.Get,
failureStatus: HealthStatus.Unhealthy,
tags: new string[] { "security", "authorisation" })
.AddUrlGroup(new Uri($"{ConfigurationReader.GetValue("AppSettings", "EstateManagementApi")}/.well-known/openid-configuration"),
name: "Estate Management Service",
httpMethod: HttpMethod.Get,
failureStatus: HealthStatus.Unhealthy,
tags: new string[] { "application", "estatemanagement" });

services.AddApiVersioning(
options =>
{
Expand Down Expand Up @@ -299,8 +308,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF

Logger.Initialise(logger);

ConfigurationReader.Initialise(Startup.Configuration);

app.AddRequestLogging();
app.AddResponseLogging();
app.AddExceptionHandler();
Expand All @@ -313,6 +320,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("health", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
});

app.UseSwagger();
Expand All @@ -326,17 +338,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
}
});

//if (String.Compare(ConfigurationReader.GetValue("EventStoreSettings", "START_PROJECTIONS"),
// Boolean.TrueString,
// StringComparison.InvariantCultureIgnoreCase) == 0)
//{
// app.PreWarm(true).Wait();
//}
//else
//{
// app.PreWarm();
//}
}
}
}
10 changes: 8 additions & 2 deletions TransactionProcessor/TransactionProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="3.1.3" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="3.1.2" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="3.1.2" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
Expand All @@ -19,7 +24,8 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.4" />
<PackageReference Include="Shared" Version="0.0.15.7" />
<PackageReference Include="Shared" Version="1.0.1" />
<PackageReference Include="Shared.EventStore" Version="1.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.2" />
Expand Down