1- #define USEDATABASEEVENTSTORE //EXTEND: Set this to true if you are using a database event store in production
2-
31using System . Text . Json ;
42using System . Text . Json . Serialization ;
53using Application . Interfaces ;
97using Common ;
108using Common . Configuration ;
119using Common . Extensions ;
12- using Common . FeatureFlags ;
10+ using Common . Recording ;
1311using Domain . Common ;
1412using Domain . Common . Identity ;
1513using Domain . Interfaces ;
1917using Domain . Shared ;
2018using Infrastructure . Common ;
2119using Infrastructure . Common . Extensions ;
20+ using Infrastructure . Common . Recording ;
2221using Infrastructure . Eventing . Common . Notifications ;
2322using Infrastructure . Eventing . Common . Projections . ReadModels ;
2423using Infrastructure . Eventing . Interfaces . Notifications ;
25- using Infrastructure . External . TestingOnly . ApplicationServices ;
2624using Infrastructure . Hosting . Common ;
2725using Infrastructure . Hosting . Common . Extensions ;
2826using Infrastructure . Hosting . Common . Recording ;
4644using Microsoft . OpenApi . Models ;
4745#if TESTINGONLY
4846using 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
6351namespace 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