Skip to content

Commit

Permalink
docker compose infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Feb 9, 2024
1 parent 0fe3394 commit b37f341
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Modules.TenantIdentity.Features.Domain.TenantAggregate;

namespace Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration.TenantAggregate
namespace Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration
{
public class TenantConfiguration : IEntityTypeConfiguration<Tenant>
{
Expand All @@ -15,6 +15,8 @@ public void Configure(EntityTypeBuilder<Tenant> builder)
builder.Navigation(b => b.Invitations)
.HasField("invitations")
.UsePropertyAccessMode(PropertyAccessMode.Field);

builder.OwnsMany(t => t.Invitations);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Modules.TenantIdentity.Features.Aggregates.UserAggregate;

namespace Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration.UserAggregate
namespace Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration
{
public class UserConfiguration : IEntityTypeConfiguration<ApplicationUser>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration.UserAggregate;
using Shared.Features.Domain.Exceptions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shared.Features.EFCore.Configuration;
using Modules.TenantIdentity.Features.Aggregates.UserAggregate;
using Modules.TenantIdentity.Features.Domain.TenantAggregate;
using Modules.TenantIdentity.Features.Infrastructure.EFCore.Configuration;

namespace Modules.TenantIdentity.Features.Infrastructure.EFCore
{
Expand Down
8 changes: 4 additions & 4 deletions Source/Shared/Kernel/BuildingBlocks/IExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Shared.Kernel.BuildingBlocks
{
public interface IExecutionContext
{
bool AuthenticatedRequest { get; }

Guid UserId { get; }

Guid TenantId { get; }
Expand All @@ -16,8 +14,10 @@ public interface IExecutionContext

TenantRole TenantRole { get; }

IHostEnvironment HostingEnvironment { get; }

public Uri BaseURI { get; }

bool AuthenticatedRequest { get; }

IHostEnvironment HostingEnvironment { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static IApplicationBuilder RegisterExecutionContextMiddleware(this IAppli
executionContext.InitializeInstance(context);

await next(context);

await executionContext.CommitChangesAsync();
});

return applicationBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shared.Kernel.BuildingBlocks;
using Modules.TenantIdentity.Features.Infrastructure.EFCore;
using Shared.Kernel.BuildingBlocks.Auth;
using Shared.Kernel.BuildingBlocks;
using Shared.Kernel.Extensions.ClaimsPrincipal;
using System;
using System.Linq;
using System.Threading.Tasks;
using Modules.Subscription.Features.Infrastructure.EFCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;

namespace Web.Server.BuildingBlocks.ServerExecutionContext
{
public class ServerExecutionContext : IExecutionContext
{
private static ServerExecutionContext executionContext;
private ServerExecutionContext() { }


public bool AuthenticatedRequest { get; private set; }
public Guid UserId { get; private set; }
public Guid TenantId { get; private set; }
public SubscriptionPlanType TenantPlan { get; private set; }
public TenantRole TenantRole { get; private set; }
public IHostEnvironment HostingEnvironment { get; set; }
public Uri BaseURI { get; private set; }

public TenantIdentityDbContext TenantIdentityDbContext { get; set; }
public SubscriptionsDbContext SubscriptionsDbContext { get; set; }

public static ServerExecutionContext CreateInstance(IServiceProvider serviceProvider)
{
if (executionContext is not null)
Expand All @@ -35,6 +51,7 @@ public void InitializeInstance(HttpContext httpContext)
var addresses = server?.Features.Get<IServerAddressesFeature>();

BaseURI = new Uri(addresses?.Addresses.FirstOrDefault(a => a.Contains("https")) ?? string.Empty);
TenantIdentityDbContext = httpContext.RequestServices.GetRequiredService<TenantIdentityDbContext>();

if (httpContext.User.Identity.IsAuthenticated is false)
{
Expand All @@ -48,18 +65,15 @@ public void InitializeInstance(HttpContext httpContext)
TenantRole = httpContext.User.GetTenantRole();
}

public bool AuthenticatedRequest { get; private set; }

public Guid UserId { get; private set; }

public Guid TenantId { get; private set; }

public SubscriptionPlanType TenantPlan { get; private set; }

public TenantRole TenantRole { get; private set; }
public async Task CommitChangesAsync()
{
using var trans = TenantIdentityDbContext.Database.BeginTransaction();
await SubscriptionsDbContext.Database.UseTransactionAsync(trans.GetDbTransaction());

public IHostEnvironment HostingEnvironment { get; set; }
await TenantIdentityDbContext.SaveChangesAsync();
await SubscriptionsDbContext.SaveChangesAsync();

public Uri BaseURI { get; private set; }
await trans.CommitAsync();
}
}
}
2 changes: 1 addition & 1 deletion Source/Web/Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
},
"EFCoreConfiguration": {
"SQLServerConnectionString_Dev": "DavidEggenberger"
"SQLServerConnectionString_Dev": "Server=127.0.0.1,1433;Database=ModularMonolith;User Id=SA;Password=YourSTRONG!Passw0rd;Encrypt=False;"
},
"SubscriptionsConfiguration": {
"StripeProfessionalPlanId": "DavidEggenberger"
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.infrastructure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.4'
name: Infrastructure

services:
sqlserver:
container_name: SQLServer
image: mcr.microsoft.com/azure-sql-edge
ports:
- "1433:1433"
environment:
- SA_PASSWORD=YourSTRONG!Passw0rd
- ACCEPT_EULA=Y
volumes:
- sqlserver:/sqlserver
volumes:
sqlserver:

0 comments on commit b37f341

Please sign in to comment.