-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/use_domain_events_in_tests' of https://github.…
…com/evolutionary-architecture/evolutionary-architecture-by-example into refactor/use_domain_events_in_tests
- Loading branch information
Showing
14 changed files
with
103 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ services: | |
test: [ "CMD-SHELL", "pg_isready -U postgres" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
retries: 5 |
44 changes: 34 additions & 10 deletions
44
...s-separation/Src/Common/Fitnet.Common.Infrastructure/Modules/ModuleAvailabilityChecker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Common.Infrastructure.Modules; | ||
|
||
using Microsoft.FeatureManagement; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class ModuleAvailabilityChecker | ||
public sealed class ModuleAvailabilityChecker : IDisposable | ||
{ | ||
public static bool IsModuleEnabled(this IServiceCollection services, string module) | ||
private readonly IFeatureManager _featureManager; | ||
private readonly ServiceProvider _serviceProvider; | ||
|
||
private ModuleAvailabilityChecker(IFeatureManager featureManager, ServiceProvider serviceProvider) | ||
{ | ||
_featureManager = featureManager; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public static ModuleAvailabilityChecker Create(IConfiguration configuration) | ||
{ | ||
var buildServiceProvider = services.BuildServiceProvider(); | ||
var featureManager = buildServiceProvider.GetRequiredService<IFeatureManager>(); | ||
var featureFlagServiceProvider = BuildIsolatedFeatureFlagServiceProvider(configuration); | ||
var featureManager = featureFlagServiceProvider.GetRequiredService<IFeatureManager>(); | ||
|
||
return featureManager.IsEnabledAsync(module).GetAwaiter().GetResult(); | ||
return new ModuleAvailabilityChecker(featureManager, featureFlagServiceProvider); | ||
} | ||
|
||
public static bool IsModuleEnabled(this IApplicationBuilder applicationBuilder, string module) | ||
private static ServiceProvider BuildIsolatedFeatureFlagServiceProvider(IConfiguration configuration) => new ServiceCollection() | ||
.AddSingleton(configuration) | ||
.AddFeatureManagement() | ||
.Services | ||
.BuildServiceProvider(); | ||
|
||
public bool IsModuleEnabled(string module) => | ||
_featureManager.IsEnabledAsync(module).GetAwaiter().GetResult(); | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
var buildServiceProvider = applicationBuilder.ApplicationServices; | ||
var featureManager = buildServiceProvider.GetRequiredService<IFeatureManager>(); | ||
if (disposing) | ||
{ | ||
_serviceProvider.Dispose(); | ||
} | ||
} | ||
|
||
return featureManager.IsEnabledAsync(module).GetAwaiter().GetResult(); | ||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...on/Src/Common/Fitnet.Common.Infrastructure/Modules/ModuleAvailabilityCheckerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Common.Infrastructure.Modules; | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.FeatureManagement; | ||
|
||
public static class ModuleAvailabilityCheckerExtensions | ||
{ | ||
public static bool IsModuleEnabled(this IApplicationBuilder applicationBuilder, string module) | ||
{ | ||
using var scope = applicationBuilder.ApplicationServices.CreateScope(); | ||
var featureManager = scope.ServiceProvider.GetRequiredService<IFeatureManager>(); | ||
|
||
var enabled = featureManager.IsEnabledAsync(module).GetAwaiter().GetResult(); | ||
|
||
return enabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Chapter-2-modules-separation/Src/Fitnet/Modules/ModulesRegistry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Modules; | ||
|
||
using EvolutionaryArchitecture.Fitnet.Common.Infrastructure.Modules; | ||
using Contracts.Api; | ||
using Offers.Api; | ||
using Passes.Api; | ||
using Reports; | ||
|
||
internal static class ModulesRegistry | ||
{ | ||
internal static void AddModules(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
using var moduleAvailabilityChecker = ModuleAvailabilityChecker.Create(configuration); | ||
services.AddContracts(Module.Contracts, configuration, moduleAvailabilityChecker); | ||
services.AddPasses(Module.Passes, configuration, moduleAvailabilityChecker); | ||
services.AddOffers(Module.Offers, configuration, moduleAvailabilityChecker); | ||
services.AddReports(Module.Reports, moduleAvailabilityChecker); | ||
} | ||
|
||
internal static void RegisterModules(this WebApplication app) | ||
{ | ||
app.RegisterContracts(Module.Contracts); | ||
app.RegisterPasses(Module.Passes); | ||
app.RegisterOffers(Module.Offers); | ||
app.RegisterReports(Module.Reports); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ services: | |
test: [ "CMD-SHELL", "pg_isready -U postgres" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
retries: 5 |