-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,338 additions
and
7 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
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
61 changes: 61 additions & 0 deletions
61
src/PostalRegistry.Projections.Integration/Infrastructure/IntegrationModule.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,61 @@ | ||
namespace PostalRegistry.Projections.Integration.Infrastructure | ||
{ | ||
using System; | ||
using Autofac; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using PostalRegistry.Infrastructure; | ||
|
||
public class IntegrationModule : Module | ||
{ | ||
public IntegrationModule( | ||
IConfiguration configuration, | ||
IServiceCollection services, | ||
ILoggerFactory loggerFactory) | ||
{ | ||
var logger = loggerFactory.CreateLogger<IntegrationModule>(); | ||
var connectionString = configuration.GetConnectionString("IntegrationProjections"); | ||
|
||
var hasConnectionString = !string.IsNullOrWhiteSpace(connectionString); | ||
if (hasConnectionString) | ||
RunOnNpgSqlServer(services, connectionString); | ||
else | ||
RunInMemoryDb(services, loggerFactory, logger); | ||
|
||
logger.LogInformation( | ||
"Added {Context} to services:" + | ||
Environment.NewLine + | ||
"\tSchema: {Schema}" + | ||
Environment.NewLine + | ||
"\tTableName: {TableName}", | ||
nameof(IntegrationContext), Schema.Integration, MigrationTables.Integration); | ||
} | ||
|
||
private static void RunOnNpgSqlServer( | ||
IServiceCollection services, | ||
string backofficeProjectionsConnectionString) | ||
{ | ||
services | ||
.AddNpgsql<IntegrationContext>(backofficeProjectionsConnectionString, sqlServerOptions => | ||
{ | ||
sqlServerOptions.EnableRetryOnFailure(); | ||
sqlServerOptions.MigrationsHistoryTable(MigrationTables.Integration, Schema.Integration); | ||
}); | ||
} | ||
|
||
private static void RunInMemoryDb( | ||
IServiceCollection services, | ||
ILoggerFactory loggerFactory, | ||
ILogger logger) | ||
{ | ||
services | ||
.AddDbContext<IntegrationContext>(options => options | ||
.UseLoggerFactory(loggerFactory) | ||
.UseInMemoryDatabase(Guid.NewGuid().ToString(), _ => { })); | ||
|
||
logger.LogWarning("Running InMemory for {Context}!", nameof(IntegrationContext)); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/PostalRegistry.Projections.Integration/Infrastructure/IntegrationOptions.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,8 @@ | ||
namespace PostalRegistry.Projections.Integration.Infrastructure | ||
{ | ||
public class IntegrationOptions | ||
{ | ||
public string Namespace { get; set; } | ||
public bool Enabled { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/PostalRegistry.Projections.Integration/IntegrationContext.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,20 @@ | ||
namespace PostalRegistry.Projections.Integration | ||
{ | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner; | ||
using Microsoft.EntityFrameworkCore; | ||
using PostalRegistry.Infrastructure; | ||
|
||
public class IntegrationContext : RunnerDbContext<IntegrationContext> | ||
{ | ||
public override string ProjectionStateSchema => Schema.Integration; | ||
|
||
public DbSet<PostalLatestItem> PostalLatestItems => Set<PostalLatestItem>(); | ||
|
||
// This needs to be here to please EF | ||
public IntegrationContext() { } | ||
|
||
// This needs to be DbContextOptions<T> for Autofac! | ||
public IntegrationContext(DbContextOptions<IntegrationContext> options) | ||
: base(options) { } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/PostalRegistry.Projections.Integration/IntegrationContextMigrationFactory.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,23 @@ | ||
namespace PostalRegistry.Projections.Integration | ||
{ | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.Npgsql; | ||
using Microsoft.EntityFrameworkCore; | ||
using PostalRegistry.Infrastructure; | ||
|
||
public class IntegrationContextMigrationFactory : NpgsqlRunnerDbContextMigrationFactory<IntegrationContext> | ||
{ | ||
public IntegrationContextMigrationFactory() | ||
: base("IntegrationProjectionsAdmin", HistoryConfiguration) { } | ||
|
||
private static MigrationHistoryConfiguration HistoryConfiguration => | ||
new MigrationHistoryConfiguration | ||
{ | ||
Schema = Schema.Integration, | ||
Table = MigrationTables.Integration | ||
}; | ||
|
||
protected override IntegrationContext CreateContext( | ||
DbContextOptions<IntegrationContext> migrationContextOptions) => | ||
new IntegrationContext(migrationContextOptions); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/PostalRegistry.Projections.Integration/Migrations/20240131111518_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.