Skip to content

Commit e449ff1

Browse files
committed
fix: fixed builds
1 parent bb4e04b commit e449ff1

File tree

15 files changed

+88
-1310
lines changed

15 files changed

+88
-1310
lines changed

src/ExternalAdapters/Infrastructure.External.TestingOnly/ApplicationServices/FakeFeatureFlagProviderServiceClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.Json;
1+
#if TESTINGONLY
2+
using System.Text.Json;
23
using Common;
34
using Common.Configuration;
45
using Common.FeatureFlags;
@@ -98,4 +99,5 @@ public bool IsEnabled(Flag flag, Optional<string> tenantId, string userId)
9899
flag.Name, userId, tenantId, DefaultEnabled);
99100
return DefaultEnabled;
100101
}
101-
}
102+
}
103+
#endif

src/Framework/Infrastructure/Infrastructure.Common/Recording/QueuedAuditReporter.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
#if !TESTINGONLY
2-
using Infrastructure.Persistence.Common.ApplicationServices;
3-
#if HOSTEDONAZURE
4-
using Infrastructure.External.Persistence.Azure.ApplicationServices;
5-
#elif HOSTEDONAWS
6-
using Infrastructure.External.Persistence.AWS.ApplicationServices;
7-
#endif
8-
#else
9-
using Infrastructure.Persistence.Interfaces;
10-
#endif
11-
using Application.Interfaces.Services;
1+
using Application.Interfaces.Services;
122
using Application.Persistence.Shared;
133
using Application.Persistence.Shared.ReadModels;
144
using Common;
@@ -17,6 +7,7 @@
177
using Common.Recording;
188
using Domain.Interfaces;
199
using Domain.Interfaces.Services;
10+
using Infrastructure.Persistence.Interfaces;
2011
using Infrastructure.Persistence.Shared.ApplicationServices;
2112

2213
namespace Infrastructure.Common.Recording;
@@ -30,21 +21,12 @@ public class QueuedAuditReporter : IAuditReporter
3021
private readonly IHostSettings _hostSettings;
3122
private readonly IAuditMessageQueueRepository _repository;
3223

33-
// ReSharper disable once UnusedParameter.Local
3424
public QueuedAuditReporter(IDependencyContainer container, IConfigurationSettings settings,
3525
IHostSettings hostSettings)
3626
: this(new AuditMessageQueueRepository(NoOpRecorder.Instance,
3727
container.GetRequiredService<IHostSettings>(),
3828
container.GetRequiredService<IMessageQueueMessageIdFactory>(),
39-
#if !TESTINGONLY
40-
#if HOSTEDONAZURE
41-
AzureStorageAccountQueueStore.Create(NoOpRecorder.Instance, AzureStorageAccountStoreOptions.Credentials(settings))
42-
#elif HOSTEDONAWS
43-
AWSSQSQueueStore.Create(NoOpRecorder.Instance, settings)
44-
#endif
45-
#else
4629
container.GetRequiredServiceForPlatform<IQueueStore>()
47-
#endif
4830
), hostSettings)
4931
{
5032
}

src/Framework/Infrastructure/Infrastructure.Common/Recording/QueuedUsageReporter.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
#if !TESTINGONLY
2-
using Infrastructure.Persistence.Common.ApplicationServices;
3-
#if HOSTEDONAZURE
4-
using Infrastructure.External.Persistence.Azure.ApplicationServices;
5-
#elif HOSTEDONAWS
6-
using Infrastructure.External.Persistence.AWS.ApplicationServices;
7-
#endif
8-
#else
9-
using Infrastructure.Persistence.Interfaces;
10-
#endif
11-
using Application.Interfaces;
1+
using Application.Interfaces;
122
using Application.Interfaces.Services;
133
using Application.Persistence.Shared;
144
using Application.Persistence.Shared.ReadModels;
@@ -18,6 +8,7 @@
188
using Common.Recording;
199
using Domain.Interfaces;
2010
using Domain.Interfaces.Services;
11+
using Infrastructure.Persistence.Interfaces;
2112
using Infrastructure.Persistence.Shared.ApplicationServices;
2213

2314
namespace Infrastructure.Common.Recording;
@@ -37,15 +28,7 @@ public QueuedUsageReporter(IDependencyContainer container, IConfigurationSetting
3728
: this(new UsageMessageQueue(NoOpRecorder.Instance,
3829
container.GetRequiredService<IHostSettings>(),
3930
container.GetRequiredService<IMessageQueueMessageIdFactory>(),
40-
#if !TESTINGONLY
41-
#if HOSTEDONAZURE
42-
AzureStorageAccountQueueStore.Create(NoOpRecorder.Instance, AzureStorageAccountStoreOptions.Credentials(settings))
43-
#elif HOSTEDONAWS
44-
AWSSQSQueueStore.Create(NoOpRecorder.Instance, settings)
45-
#endif
46-
#else
4731
container.GetRequiredServiceForPlatform<IQueueStore>()
48-
#endif
4932
), hostSettings)
5033
{
5134
}

src/Framework/Infrastructure/Infrastructure.Hosting.Common/Recording/HostRecorder.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,7 @@ private static ICrashReporter GetCrashReporter(IDependencyContainer container, I
280280
return options.CrashReporting switch
281281
{
282282
CrashReporterOption.None => new NoOpCrashReporter(),
283-
CrashReporterOption.Cloud =>
284-
#if TESTINGONLY
285-
new NoOpCrashReporter(),
286-
#else
287-
#if HOSTEDONAZURE
288-
new ApplicationInsightsCrashReporter(container),
289-
#elif HOSTEDONAWS
290-
new AWSCloudWatchCrashReporter(logger),
291-
#endif
292-
#endif
283+
CrashReporterOption.Cloud => container.GetRequiredService<ICrashReporter>(),
293284
_ => throw new ArgumentOutOfRangeException(nameof(options.MetricReporting))
294285
};
295286
}
@@ -313,16 +304,7 @@ private static IMetricReporter GetMetricReporter(IDependencyContainer container,
313304
return options.MetricReporting switch
314305
{
315306
MetricReporterOption.None => new NoOpMetricReporter(),
316-
MetricReporterOption.Cloud =>
317-
#if TESTINGONLY
318-
new NoOpMetricReporter(),
319-
#else
320-
#if HOSTEDONAZURE
321-
new ApplicationInsightsMetricReporter(container),
322-
#elif HOSTEDONAWS
323-
new AWSCloudWatchMetricReporter(container),
324-
#endif
325-
#endif
307+
MetricReporterOption.Cloud => container.GetRequiredService<IMetricReporter>(),
326308
_ => throw new ArgumentOutOfRangeException(nameof(options.MetricReporting))
327309
};
328310
}

src/Framework/Infrastructure/Infrastructure.Web.Hosting.Common/Extensions/HostExtensions.cs

Lines changed: 11 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USEDATABASEEVENTSTORE //EXTEND: Set this to true if you are using a database event store in production
2-
31
using System.Text.Json;
42
using System.Text.Json.Serialization;
53
using Application.Interfaces;
@@ -9,7 +7,7 @@
97
using Common;
108
using Common.Configuration;
119
using Common.Extensions;
12-
using Common.FeatureFlags;
10+
using Common.Recording;
1311
using Domain.Common;
1412
using Domain.Common.Identity;
1513
using Domain.Interfaces;
@@ -19,10 +17,10 @@
1917
using Domain.Shared;
2018
using Infrastructure.Common;
2119
using Infrastructure.Common.Extensions;
20+
using Infrastructure.Common.Recording;
2221
using Infrastructure.Eventing.Common.Notifications;
2322
using Infrastructure.Eventing.Common.Projections.ReadModels;
2423
using Infrastructure.Eventing.Interfaces.Notifications;
25-
using Infrastructure.External.TestingOnly.ApplicationServices;
2624
using Infrastructure.Hosting.Common;
2725
using Infrastructure.Hosting.Common.Extensions;
2826
using Infrastructure.Hosting.Common.Recording;
@@ -46,18 +44,8 @@
4644
using Microsoft.OpenApi.Models;
4745
#if TESTINGONLY
4846
using Domain.Events.Shared.TestingOnly;
49-
50-
#else
51-
#if HOSTEDONAZURE
52-
using Infrastructure.External.Persistence.Azure.ApplicationServices;
53-
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
54-
using Microsoft.ApplicationInsights.Extensibility;
55-
56-
#elif HOSTEDONAWS
57-
using Amazon.XRay.Recorder.Core;
58-
using Amazon.XRay.Recorder.Handlers.AwsSdk;
59-
using Infrastructure.Persistence.Common.ApplicationServices;
60-
#endif
47+
using Common.FeatureFlags;
48+
using Infrastructure.External.TestingOnly.ApplicationServices;
6149
#endif
6250

6351
namespace Infrastructure.Web.Hosting.Common.Extensions;
@@ -120,12 +108,16 @@ void RegisterSharedServices()
120108
services.AddAntiforgery();
121109
services.AddHttpContextAccessor();
122110

123-
// EXTEND: Default technology adapters
111+
// EXTEND: Any global technology adapters
112+
services.AddSingleton<ICrashReporter, NoOpCrashReporter>();
113+
services.AddSingleton<IMetricReporter, NoOpMetricReporter>();
114+
#if TESTINGONLY
124115
services.AddSingleton<IFeatureFlags>(c => new FakeFeatureFlagProviderServiceClient(
125116
c.GetRequiredService<IRecorder>(),
126117
c.GetRequiredServiceForPlatform<IConfigurationSettings>(),
127118
c.GetRequiredService<IHttpClientFactory>(),
128119
c.GetRequiredService<JsonSerializerOptions>()));
120+
#endif
129121
}
130122

131123
void RegisterConfiguration(bool isMultiTenanted)
@@ -157,30 +149,6 @@ void RegisterConfiguration(bool isMultiTenanted)
157149

158150
void RegisterRecording()
159151
{
160-
#if HOSTEDONAZURE
161-
#if !TESTINGONLY
162-
// Note: Apply sampling, but never sample any Exceptions
163-
services.Configure<TelemetryConfiguration>(config =>
164-
{
165-
var builder = config.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
166-
builder.UseAdaptiveSampling(10, "Exception");
167-
builder.Build();
168-
});
169-
170-
services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
171-
{
172-
// We always want this to be false
173-
// See https://learn.microsoft.com/en-us/azure/azure-monitor/app/sampling-classic-api#configure-sampling-settings
174-
EnableAdaptiveSampling = false
175-
});
176-
#endif
177-
#elif HOSTEDONAWS
178-
#if !TESTINGONLY
179-
AWSXRayRecorder.InitializeInstance(appBuilder.Configuration);
180-
AWSSDKHandler.RegisterXRayForAllServices();
181-
#endif
182-
services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
183-
#endif
184152
services.AddLogging(builder =>
185153
{
186154
builder.ClearProviders();
@@ -193,12 +161,6 @@ void RegisterRecording()
193161
options.IncludeScopes = false;
194162
});
195163
builder.AddDebug();
196-
#else
197-
#if HOSTEDONAZURE
198-
builder.AddApplicationInsights();
199-
#elif HOSTEDONAWS
200-
builder.AddLambdaLogger();
201-
#endif
202164
#endif
203165
builder.AddEventSourceLogger();
204166
});
@@ -428,7 +390,8 @@ void RegisterApiDocumentation(string name, string version, bool usesApiDocumenta
428390
Type = SecuritySchemeType.ApiKey,
429391
Name = HttpConstants.QueryParams.APIKey,
430392
Description =
431-
Resources.HostExtensions_ApiDocumentation_APIKeyQueryDescription.Format(HttpConstants.QueryParams
393+
Resources.HostExtensions_ApiDocumentation_APIKeyQueryDescription.Format(HttpConstants
394+
.QueryParams
432395
.APIKey),
433396
In = ParameterLocation.Query,
434397
Scheme = APIKeyAuthenticationHandler.AuthenticationScheme
@@ -559,101 +522,6 @@ void RegisterPersistence(bool usesQueues, bool isMultiTenanted)
559522
}));
560523
#if TESTINGONLY
561524
TestingOnlyHostExtensions.RegisterStoreForTestingOnly(services, usesQueues, isMultiTenanted);
562-
#else
563-
#if HOSTEDONAZURE
564-
// EXTEND: Add your production persistence stores here
565-
#if USEDATABASEEVENTSTORE
566-
services.AddForPlatform<IDataStore, IEventStore, AzureSqlServerStore>(c =>
567-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
568-
AzureSqlServerStoreOptions.Credentials(c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
569-
#else
570-
services.AddSingleton<IKurrentEventStoreClient>(c =>
571-
new SharedKurrentEventStoreClient(c.GetRequiredServiceForPlatform<IConfigurationSettings>()));
572-
services.AddForPlatform<IEventStore>(c =>
573-
KurrentEventStore.Create(c.GetRequiredService<IRecorder>(),
574-
KurrentEventStoreOptions.SharedClient(c.GetRequiredService<IKurrentEventStoreClient>())));
575-
services.AddForPlatform<IDataStore>(c =>
576-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
577-
AzureSqlServerStoreOptions.Credentials(c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
578-
#endif
579-
services.AddForPlatform<IBlobStore>(c =>
580-
AzureStorageAccountBlobStore.Create(c.GetRequiredService<IRecorder>(),
581-
AzureStorageAccountStoreOptions.Credentials(
582-
c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
583-
services.AddForPlatform<IQueueStore>(c =>
584-
AzureStorageAccountQueueStore.Create(c.GetRequiredService<IRecorder>(),
585-
AzureStorageAccountStoreOptions.Credentials(
586-
c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
587-
services.AddForPlatform<IMessageBusStore>(c =>
588-
AzureServiceBusStore.Create(c.GetRequiredService<IRecorder>(),
589-
AzureServiceBusStoreOptions.Credentials(
590-
c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
591-
592-
if (isMultiTenanted)
593-
{
594-
#if USEDATABASEEVENTSTORE
595-
services.AddPerHttpRequest<IDataStore, IEventStore, AzureSqlServerStore>(c =>
596-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
597-
AzureSqlServerStoreOptions.Credentials(
598-
c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
599-
#else
600-
services.AddPerHttpRequest<IEventStore>(c =>
601-
KurrentEventStore.Create(c.GetRequiredService<IRecorder>(),
602-
KurrentEventStoreOptions.SharedClient(c.GetRequiredService<IKurrentEventStoreClient>())));
603-
services.AddPerHttpRequest<IDataStore>(c =>
604-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
605-
AzureSqlServerStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
606-
#endif
607-
services.AddPerHttpRequest<IBlobStore>(c =>
608-
AzureStorageAccountBlobStore.Create(c.GetRequiredService<IRecorder>(),
609-
AzureStorageAccountStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
610-
services.AddPerHttpRequest<IQueueStore>(c =>
611-
AzureStorageAccountQueueStore.Create(c.GetRequiredService<IRecorder>(),
612-
AzureStorageAccountStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
613-
services.AddPerHttpRequest<IMessageBusStore>(c =>
614-
AzureServiceBusStore.Create(c.GetRequiredService<IRecorder>(),
615-
AzureServiceBusStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
616-
}
617-
else
618-
{
619-
#if USEDATABASEEVENTSTORE
620-
services.AddSingleton<IDataStore, IEventStore, AzureSqlServerStore>(c =>
621-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
622-
AzureSqlServerStoreOptions.Credentials(
623-
c.GetRequiredServiceForPlatform<IConfigurationSettings>())));
624-
#else
625-
services.AddSingleton<IEventStore>(c =>
626-
KurrentEventStore.Create(c.GetRequiredService<IRecorder>(),
627-
KurrentEventStoreOptions.SharedClient(c.GetRequiredService<IKurrentEventStoreClient>())));
628-
services.AddSingleton<IDataStore>(c =>
629-
AzureSqlServerStore.Create(c.GetRequiredService<IRecorder>(),
630-
AzureSqlServerStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
631-
#endif
632-
services.AddSingleton<IBlobStore>(c =>
633-
AzureStorageAccountBlobStore.Create(c.GetRequiredService<IRecorder>(),
634-
AzureStorageAccountStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
635-
services.AddSingleton<IQueueStore>(c =>
636-
AzureStorageAccountQueueStore.Create(c.GetRequiredService<IRecorder>(),
637-
AzureStorageAccountStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
638-
services.AddSingleton<IMessageBusStore>(c =>
639-
AzureServiceBusStore.Create(c.GetRequiredService<IRecorder>(),
640-
AzureServiceBusStoreOptions.Credentials(c.GetRequiredService<IConfigurationSettings>())));
641-
}
642-
#elif HOSTEDONAWS
643-
//HACK: Need AWS production stores here like DynamoDbDataStore
644-
services.AddForPlatform<IDataStore, IEventStore, IBlobStore, IQueueStore, IMessageBusStore, NoOpStore>(_ =>
645-
NoOpStore.Instance);
646-
if (isMultiTenanted)
647-
{
648-
services.AddPerHttpRequest<IDataStore, IEventStore, IBlobStore, IQueueStore, IMessageBusStore, NoOpStore>(_ =>
649-
NoOpStore.Instance);
650-
}
651-
else
652-
{
653-
services.AddSingleton<IDataStore, IEventStore, IBlobStore, IQueueStore, IMessageBusStore, NoOpStore>(_ =>
654-
NoOpStore.Instance);
655-
}
656-
#endif
657525
#endif
658526
}
659527

0 commit comments

Comments
 (0)