Skip to content

Commit 56a98c8

Browse files
Merge pull request #222 from TransactionProcessing/task/#216_middleware_registry
Task/#216 middleware registry
2 parents 0f49e7e + 8321664 commit 56a98c8

3 files changed

Lines changed: 26 additions & 40 deletions

File tree

CallbackHander.Testing/TestData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static TokenResponse TokenResponse()
3939
["SecurityConfiguration:Authority"] = "https://127.0.0.1",
4040
["AppSettings:EstateManagementApi"] = "http://127.0.0.1",
4141
["AppSettings:SecurityService"] = "http://127.0.0.1",
42+
["AppSettings:TransactionProcessorApi"] = "http://127.0.0.1",
4243
["AppSettings:ContractProductFeeCacheExpiryInHours"] = "",
4344
["AppSettings:ContractProductFeeCacheEnabled"] = "",
4445
["ConnectionStrings:HealthCheck"] = "HealthCheck",

CallbackHandler.Tests/BootstrapperTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private IConfigurationRoot SetupMemoryConfiguration()
4848
configuration.Add("AppSettings:SecurityService", "http://127.0.0.1");
4949
configuration.Add("AppSettings:MessagingServiceApi", "http://127.0.0.1");
5050
configuration.Add("AppSettings:DatabaseEngine", "SqlServer");
51+
configuration.Add("AppSettings:TransactionProcessorApi","http://127.0.0.1");
5152

5253
builder.AddInMemoryCollection(configuration);
5354

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using KurrentDB.Client;
22
using Microsoft.Extensions.Logging;
33
using Microsoft.OpenApi;
4+
using Shared.Extensions;
5+
using Swashbuckle.AspNetCore.SwaggerGen;
46

57
namespace CallbackHandler.Bootstrapper;
68

@@ -32,40 +34,10 @@ public MiddlewareRegistry()
3234
String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
3335
KurrentDBClientSettings eventStoreSettings = KurrentDBClientSettings.Create(connectionString);
3436

35-
this.AddHealthChecks().AddEventStore(eventStoreSettings,
36-
userCredentials: eventStoreSettings.DefaultCredentials,
37-
name: "Eventstore",
38-
failureStatus: HealthStatus.Unhealthy,
39-
tags: new[] { "db", "eventstore" });
37+
this.AddHealthChecks().AddEventStore(eventStoreSettings, userCredentials: eventStoreSettings.DefaultCredentials,
38+
name: "Eventstore", failureStatus: HealthStatus.Unhealthy, tags: new[] { "db", "eventstore" });
4039

41-
this.AddSwaggerGen(c =>
42-
{
43-
c.SwaggerDoc("v1", new OpenApiInfo
44-
{
45-
Title = "Callback Handler API",
46-
Version = "1.0",
47-
Description = "A REST Api to handle callback requests from external parties API's.",
48-
Contact = new OpenApiContact
49-
{
50-
Name = "Stuart Ferguson",
51-
Email = "golfhandicapping@btinternet.com"
52-
}
53-
});
54-
// add a custom operation filter which sets default values
55-
c.OperationFilter<SwaggerDefaultValues>();
56-
c.ExampleFilters();
57-
58-
//Locate the XML files being generated by ASP.NET...
59-
DirectoryInfo directory = new(AppContext.BaseDirectory);
60-
FileInfo[] xmlFiles = directory.GetFiles("*.xml");
61-
62-
//... and tell Swagger to use those XML comments.
63-
foreach (FileInfo fileInfo in xmlFiles)
64-
{
65-
c.IncludeXmlComments(fileInfo.FullName);
66-
}
67-
68-
});
40+
this.AddSwaggerGen(AddSwaggerAction);
6941
this.AddSwaggerExamples();
7042

7143
this.AddControllers().AddNewtonsoftJson(options =>
@@ -83,16 +55,28 @@ public MiddlewareRegistry()
8355
bool logRequests = ConfigurationReader.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogRequests", true);
8456
bool logResponses = ConfigurationReader.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogResponses", true);
8557
LogLevel middlewareLogLevel = ConfigurationReader.GetValueOrDefault<LogLevel>("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning);
58+
59+
this.AddSingleton(new RequestResponseMiddlewareLoggingConfig(middlewareLogLevel, logRequests, logResponses));
8660

87-
RequestResponseMiddlewareLoggingConfig config =
88-
new(middlewareLogLevel, logRequests, logResponses);
89-
90-
this.AddSingleton(config);
91-
92-
this.ConfigureHttpJsonOptions(options =>
93-
{
61+
this.ConfigureHttpJsonOptions(options => {
9462
options.SerializerOptions.PropertyNamingPolicy = new SnakeCaseNamingPolicy();
9563
options.SerializerOptions.PropertyNameCaseInsensitive = true; // optional, but safer
9664
});
9765
}
66+
67+
private void AddSwaggerAction(SwaggerGenOptions c) {
68+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Callback Handler API", Version = "1.0", Description = "A REST Api to handle callback requests from external parties API's.", Contact = new OpenApiContact { Name = "Stuart Ferguson", Email = "golfhandicapping@btinternet.com" } });
69+
// add a custom operation filter which sets default values
70+
c.OperationFilter<SwaggerDefaultValues>();
71+
c.ExampleFilters();
72+
73+
//Locate the XML files being generated by ASP.NET...
74+
DirectoryInfo directory = new(AppContext.BaseDirectory);
75+
FileInfo[] xmlFiles = directory.GetFiles("*.xml");
76+
77+
//... and tell Swagger to use those XML comments.
78+
foreach (FileInfo fileInfo in xmlFiles) {
79+
c.IncludeXmlComments(fileInfo.FullName);
80+
}
81+
}
9882
}

0 commit comments

Comments
 (0)