diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs index 229e7442..f5f3ada3 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs @@ -3,7 +3,6 @@ using Modules.Subscription.Features.Infrastructure.EFCore; using Modules.Subscriptions.IntegrationEvents; using Shared.Features.Messaging.Command; -using Shared.Features.Messaging.IntegrationEvent; using Shared.Features.Server; using Stripe; @@ -17,26 +16,16 @@ public class CreateTrialingSubscription : ICommand public Stripe.Subscription CreatedStripeSubscription { get; set; } } - public class CreateTrialingSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler + public class CreateTrialingSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly SubscriptionsDbContext subscriptionDbContext; - private readonly SubscriptionsConfiguration subscriptionConfiguration; - - public CreateTrialingSubscriptionCommandHandler( - SubscriptionsDbContext subscriptionDbContext, - SubscriptionsConfiguration subscriptionConfiguration, - IServiceProvider serviceProvider): base(serviceProvider) - { - this.subscriptionDbContext = subscriptionDbContext; - this.subscriptionConfiguration = subscriptionConfiguration; - } + public CreateTrialingSubscriptionCommandHandler(IServiceProvider serviceProvider): base(serviceProvider) { } public async Task HandleAsync(CreateTrialingSubscription command, CancellationToken cancellationToken) { - var subscriptionType = subscriptionConfiguration.Subscriptions.First(s => s.StripePriceId == command.CreatedStripeSubscription.Items.First().Price.Id).Type; + var subscriptionType = module.SubscriptionsConfiguration.Subscriptions.First(s => s.StripePriceId == command.CreatedStripeSubscription.Items.First().Price.Id).Type; var customer = await new CustomerService().GetAsync(command.CreatedStripeSubscription.CustomerId); - var stripeCustomer = await subscriptionDbContext.StripeCustomers.FirstAsync(sc => sc.StripePortalCustomerId == customer.Id); + var stripeCustomer = await module.SubscriptionsDbContext.StripeCustomers.FirstAsync(sc => sc.StripePortalCustomerId == customer.Id); var tenantId = new Guid(command.CreatedStripeSubscription.Metadata["TenantId"]); @@ -48,9 +37,9 @@ public async Task HandleAsync(CreateTrialingSubscription command, CancellationTo tenantId, stripeCustomer); - subscriptionDbContext.StripeSubscriptions.Add(stripeSubscription); + module.SubscriptionsDbContext.StripeSubscriptions.Add(stripeSubscription); - await subscriptionDbContext.SaveChangesAsync(); + await module.SubscriptionsDbContext.SaveChangesAsync(); var userSubscriptionUpdatedEvent = new TenantSubscriptionPlanUpdatedIntegrationEvent { diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs index 04168a89..d1d761f7 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Modules.Subscription.Features.Infrastructure.EFCore; using Shared.Features.Messaging.Command; using Shared.Features.Server; @@ -10,24 +9,17 @@ public class PauseActiveSubscription : ICommand public Stripe.Subscription Subscription { get; set; } } - public class PauseActiveSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler + public class PauseActiveSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly SubscriptionsDbContext subscriptionDbContext; - - public PauseActiveSubscriptionCommandHandler( - SubscriptionsDbContext subscriptionDbContext, - IServiceProvider serviceProvider) : base(serviceProvider) - { - this.subscriptionDbContext = subscriptionDbContext; - } + public PauseActiveSubscriptionCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(PauseActiveSubscription command, CancellationToken cancellationToken) { - var stripeSubscription = await subscriptionDbContext.StripeSubscriptions.FirstAsync(stripeSubscription => stripeSubscription.StripePortalSubscriptionId == command.Subscription.Id); + var stripeSubscription = await module.SubscriptionsDbContext.StripeSubscriptions.FirstAsync(stripeSubscription => stripeSubscription.StripePortalSubscriptionId == command.Subscription.Id); stripeSubscription.Status = StripeSubscriptionStatus.Paused; - await subscriptionDbContext.SaveChangesAsync(cancellationToken); + await module.SubscriptionsDbContext.SaveChangesAsync(cancellationToken); } } } diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs index a4e066dc..476eefa9 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Modules.Subscription.Features.Infrastructure.EFCore; using Shared.Features.Messaging.Command; using Shared.Features.Server; @@ -10,20 +9,13 @@ public class UpdateSubscriptionPeriod : ICommand public Stripe.Subscription Subscription { get; set; } } - public class UpdateSubscriptionPerioEndCommandHandler : ServerExecutionBase, ICommandHandler + public class UpdateSubscriptionPerioEndCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly SubscriptionsDbContext subscriptionDbContext; - - public UpdateSubscriptionPerioEndCommandHandler( - SubscriptionsDbContext subscriptionDbContext, - IServiceProvider serviceProvider) : base(serviceProvider) - { - this.subscriptionDbContext = subscriptionDbContext; - } + public UpdateSubscriptionPerioEndCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(UpdateSubscriptionPeriod command, CancellationToken cancellationToken) { - var stripeSubscription = await subscriptionDbContext.StripeSubscriptions.FirstAsync(stripeSubscription => stripeSubscription.StripePortalSubscriptionId == command.Subscription.Id); + var stripeSubscription = await module.SubscriptionsDbContext.StripeSubscriptions.FirstAsync(stripeSubscription => stripeSubscription.StripePortalSubscriptionId == command.Subscription.Id); if (stripeSubscription.Status != StripeSubscriptionStatus.Active) { @@ -31,7 +23,7 @@ public async Task HandleAsync(UpdateSubscriptionPeriod command, CancellationToke } stripeSubscription.ExpirationDate = command.Subscription.CurrentPeriodEnd; - await subscriptionDbContext.SaveChangesAsync(cancellationToken); + await module.SubscriptionsDbContext.SaveChangesAsync(cancellationToken); } } } diff --git a/Source/Modules/Subscriptions/Features/SubscriptionsModule.cs b/Source/Modules/Subscriptions/Features/SubscriptionsModule.cs index 7b21d400..fd58d7b0 100644 --- a/Source/Modules/Subscriptions/Features/SubscriptionsModule.cs +++ b/Source/Modules/Subscriptions/Features/SubscriptionsModule.cs @@ -1,4 +1,6 @@ -using Shared.Features.Modules; +using Modules.Subscription.Features.Infrastructure.Configuration; +using Modules.Subscription.Features.Infrastructure.EFCore; +using Shared.Features.Modules; using System.Reflection; namespace Modules.Subscriptions.Features @@ -6,5 +8,13 @@ namespace Modules.Subscriptions.Features public class SubscriptionsModule : IModule { public Assembly FeaturesAssembly => typeof(SubscriptionsModule).Assembly; + public SubscriptionsConfiguration SubscriptionsConfiguration { get; set; } + public SubscriptionsDbContext SubscriptionsDbContext { get; set; } + + public SubscriptionsModule(SubscriptionsConfiguration configuration, SubscriptionsDbContext dbContext) + { + SubscriptionsConfiguration = configuration; + SubscriptionsDbContext = dbContext; + } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/AddUserToTenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/AddUserToTenant.cs index 8de9c1ed..cd919627 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/AddUserToTenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/AddUserToTenant.cs @@ -1,5 +1,5 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Command; +using Shared.Features.Messaging.Command; +using Shared.Features.Server; using Shared.Kernel.BuildingBlocks.Auth; using System.Threading; @@ -11,21 +11,17 @@ public class AddUserToTenant : ICommand public Guid UserId { get; set; } public TenantRole Role { get; set; } } - public class AddUserToTenantCommandHandler : ICommandHandler + public class AddUserToTenantCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public AddUserToTenantCommandHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public AddUserToTenantCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(AddUserToTenant command, CancellationToken cancellationToken) { - var tenant = await tenantIdentityDbContext.GetTenantByIdAsync(command.TenantId); + var tenant = await module.TenantIdentityDbContext.GetTenantByIdAsync(command.TenantId); tenant.AddUser(command.UserId, command.Role); - await tenantIdentityDbContext.SaveChangesAsync(cancellationToken); + await module.TenantIdentityDbContext.SaveChangesAsync(cancellationToken); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/CreateTenantWithAdmin.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/CreateTenantWithAdmin.cs index 411894dd..a8537f8c 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/CreateTenantWithAdmin.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/CreateTenantWithAdmin.cs @@ -1,7 +1,7 @@ using Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Domain; -using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Modules.TenantIdentity.Web.Shared.DTOs.Tenant; using Shared.Features.Messaging.Command; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Commands @@ -12,20 +12,16 @@ public class CreateTenantWithAdmin : ICommand public Guid AdminId { get; set; } } - public class CreateTenantWithAdminCommandHandler : ICommandHandler + public class CreateTenantWithAdminCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public CreateTenantWithAdminCommandHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public CreateTenantWithAdminCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(CreateTenantWithAdmin createTenant, CancellationToken cancellationToken) { var tenant = Tenant.CreateTenantWithAdmin(createTenant.Name, Guid.Empty); - tenantIdentityDbContext.Tenants.Add(tenant); - await tenantIdentityDbContext.SaveChangesAsync(cancellationToken); + module.TenantIdentityDbContext.Tenants.Add(tenant); + await module.TenantIdentityDbContext.SaveChangesAsync(cancellationToken); return tenant.ToDTO(); } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/DeleteTenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/DeleteTenant.cs index 00103997..23b2607a 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/DeleteTenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/DeleteTenant.cs @@ -1,8 +1,8 @@ using Microsoft.EntityFrameworkCore; -using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Shared.Features.Messaging.Command; using Shared.Features.Domain.Exceptions; using System.Threading; +using Shared.Features.Server; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Commands { @@ -11,18 +11,13 @@ public class DeleteTenant : ICommand public Guid TenantId { get; set; } } - public class DeleteTenantCommandHandler : ICommandHandler + public class DeleteTenantCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - - public DeleteTenantCommandHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public DeleteTenantCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(DeleteTenant command, CancellationToken cancellationToken) { - var tenant = await tenantIdentityDbContext.Tenants.SingleAsync(t => t.TenantId == command.TenantId); + var tenant = await module.TenantIdentityDbContext.Tenants.SingleAsync(t => t.TenantId == command.TenantId); if (tenant == null) { throw new NotFoundException(); @@ -30,8 +25,8 @@ public async Task HandleAsync(DeleteTenant command, CancellationToken cancellati tenant.ThrowIfUserCantDeleteTenant(); - tenantIdentityDbContext.Entry(tenant.Id).State = EntityState.Deleted; - await tenantIdentityDbContext.SaveChangesAsync(); + module.TenantIdentityDbContext.Entry(tenant.Id).State = EntityState.Deleted; + await module.TenantIdentityDbContext.SaveChangesAsync(); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/RemoveUserFromTenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/RemoveUserFromTenant.cs index daf25d30..d547d1b5 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/RemoveUserFromTenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/RemoveUserFromTenant.cs @@ -1,5 +1,5 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Command; +using Shared.Features.Messaging.Command; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Commands @@ -10,23 +10,18 @@ public class RemoveUserFromTenant : ICommand public Guid TenantId { get; set; } } - public class RemoveUserFromTenantommandHandler : ICommandHandler + public class RemoveUserFromTenantommandHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - - public RemoveUserFromTenantommandHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public RemoveUserFromTenantommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) {} public async Task HandleAsync(RemoveUserFromTenant command, CancellationToken cancellationToken) { - var tenant = await tenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId); + var tenant = await module.TenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId); tenant.DeleteTenantMembership(command.UserId); - tenantIdentityDbContext.Remove(tenant); - await tenantIdentityDbContext.SaveChangesAsync(); + module.TenantIdentityDbContext.Remove(tenant); + await module.TenantIdentityDbContext.SaveChangesAsync(); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs index 6b3e956d..458cd6e6 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs @@ -1,5 +1,5 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Command; +using Shared.Features.Messaging.Command; +using Shared.Features.Server; using Shared.Kernel.BuildingBlocks.Auth; using System.Threading; @@ -11,20 +11,16 @@ public class UpdateTenantMembership : ICommand public Guid UserId { get; set; } public TenantRole Role { get; set; } } - public class UpdateTenantMembershipCommandHandler : ICommandHandler + public class UpdateTenantMembershipCommandHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public UpdateTenantMembershipCommandHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public UpdateTenantMembershipCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(UpdateTenantMembership command, CancellationToken cancellationToken) { - var tenant = await tenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId); + var tenant = await module.TenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId); tenant.ChangeRoleOfTenantMember(command.UserId, command.Role); - await tenantIdentityDbContext.SaveChangesAsync(); + await module.TenantIdentityDbContext.SaveChangesAsync(); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs index 45120358..a6b543ff 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs @@ -1,26 +1,21 @@ using Microsoft.EntityFrameworkCore; using Modules.Subscriptions.IntegrationEvents; -using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Shared.Features.Messaging.IntegrationEvent; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.IntegrationEvents { - public class TenantSubscriptionUpdatedIntegrationEventHandler : IIntegrationEventHandler + public class TenantSubscriptionUpdatedIntegrationEventHandler : ServerExecutionBase, IIntegrationEventHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - - public TenantSubscriptionUpdatedIntegrationEventHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public TenantSubscriptionUpdatedIntegrationEventHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(TenantSubscriptionPlanUpdatedIntegrationEvent integrationEvent, CancellationToken cancellation) { - var tenant = await tenantIdentityDbContext.Tenants.FirstAsync(tenant => tenant.Id == integrationEvent.TenantId); + var tenant = await module.TenantIdentityDbContext.Tenants.FirstAsync(tenant => tenant.Id == integrationEvent.TenantId); tenant.SubscriptionPlanType = integrationEvent.SubscriptionPlanType; - await tenantIdentityDbContext.SaveChangesAsync(); + await module.TenantIdentityDbContext.SaveChangesAsync(); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetAllTenantMembershipsOfUser.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetAllTenantMembershipsOfUser.cs index 2e9aba38..f83f00f2 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetAllTenantMembershipsOfUser.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetAllTenantMembershipsOfUser.cs @@ -2,6 +2,7 @@ using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Modules.TenantIdentity.Web.Shared.DTOs.Tenant; using Shared.Features.Messaging.Query; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Queries @@ -10,17 +11,13 @@ public class GetAllTenantMembershipsOfUser : IQuery> { public Guid UserId { get; set; } } - public class GetAllTenantMembershipsOfUserQueryHandler : IQueryHandler> + public class GetAllTenantMembershipsOfUserQueryHandler : ServerExecutionBase, IQueryHandler> { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public GetAllTenantMembershipsOfUserQueryHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public GetAllTenantMembershipsOfUserQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task> HandleAsync(GetAllTenantMembershipsOfUser query, CancellationToken cancellation) { - var tenantMemberships = await tenantIdentityDbContext.TenantMeberships.Where(tm => tm.UserId == query.UserId).ToListAsync(); + var tenantMemberships = await module.TenantIdentityDbContext.TenantMeberships.Where(tm => tm.UserId == query.UserId).ToListAsync(); return tenantMemberships.Select(tm => tm.ToDTO()).ToList(); } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantByID.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantByID.cs index a768ef1f..22f09478 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantByID.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantByID.cs @@ -1,6 +1,7 @@ using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Modules.TenantIdentity.Web.Shared.DTOs.Tenant; using Shared.Features.Messaging.Query; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Queries @@ -9,17 +10,13 @@ public class GetTenantByID : IQuery { public Guid TenantId { get; set; } } - public class GetTenantByIdQueryHandler : IQueryHandler + public class GetTenantByIdQueryHandler : ServerExecutionBase, IQueryHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public GetTenantByIdQueryHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public GetTenantByIdQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(GetTenantByID query, CancellationToken cancellation) { - var tenant = await tenantIdentityDbContext.GetTenantByIdAsync(query.TenantId); + var tenant = await module.TenantIdentityDbContext.GetTenantByIdAsync(query.TenantId); return tenant.ToDTO(); } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantDetailsByID.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantDetailsByID.cs index a0b7372d..944c1fbe 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantDetailsByID.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantDetailsByID.cs @@ -2,6 +2,7 @@ using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Modules.TenantIdentity.Web.Shared.DTOs.Tenant; using Shared.Features.Messaging.Query; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Queries @@ -10,17 +11,13 @@ public class GetTenantDetailsByID : IQuery { public Guid TenantId { get; set; } } - public class GetTenantDetailsByIDQueryHandler : IQueryHandler + public class GetTenantDetailsByIDQueryHandler : ServerExecutionBase, IQueryHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public GetTenantDetailsByIDQueryHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public GetTenantDetailsByIDQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(GetTenantDetailsByID query, CancellationToken cancellation) { - var tenantDetail = await tenantIdentityDbContext.Tenants.Where(t => t.TenantId == query.TenantId).SingleAsync(); + var tenantDetail = await module.TenantIdentityDbContext.Tenants.Where(t => t.TenantId == query.TenantId).SingleAsync(); return tenantDetail.ToDetailDTO(); } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantMembershipQuery.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantMembershipQuery.cs index 62cb43be..cebf6f77 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantMembershipQuery.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/TenantAggregate/Application/Queries/GetTenantMembershipQuery.cs @@ -2,6 +2,7 @@ using System.Threading; using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Modules.TenantIdentity.Web.Shared.DTOs.Tenant; +using Shared.Features.Server; namespace Modules.TenantIdentity.Features.DomainFeatures.TenantAggregate.Application.Queries { @@ -10,17 +11,13 @@ public class GetTenantMembershipQuery : IQuery public Guid UserId { get; set; } public Guid TenantId { get; set; } } - public class GetTenantMembershipQueryHandler : IQueryHandler + public class GetTenantMembershipQueryHandler : ServerExecutionBase, IQueryHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public GetTenantMembershipQueryHandler(TenantIdentityDbContext tenantDbContext) - { - tenantIdentityDbContext = tenantDbContext; - } + public GetTenantMembershipQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(GetTenantMembershipQuery query, CancellationToken cancellation) { - var tenantMembership = tenantIdentityDbContext.TenantMeberships.Single(m => m.UserId == query.UserId); + var tenantMembership = module.TenantIdentityDbContext.TenantMeberships.Single(m => m.UserId == query.UserId); return tenantMembership.ToDTO(); } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Commands/SetSelectedTenantForUser.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Commands/SetSelectedTenantForUser.cs index 86b304c3..e786e665 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Commands/SetSelectedTenantForUser.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Commands/SetSelectedTenantForUser.cs @@ -1,5 +1,5 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Command; +using Shared.Features.Messaging.Command; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.UserAggregate.Application.Commands @@ -9,17 +9,13 @@ public class SetSelectedTenantForUser : ICommand public Guid SelectedTenantId { get; set; } public Guid UserId { get; set; } } - public class SetSelectedTenantForUserHandler : ICommandHandler + public class SetSelectedTenantForUserHandler : ServerExecutionBase, ICommandHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public SetSelectedTenantForUserHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public SetSelectedTenantForUserHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(SetSelectedTenantForUser command, CancellationToken cancellationToken) { - var user = await tenantIdentityDbContext.GetUserByIdAsync(command.UserId); + var user = await module.TenantIdentityDbContext.GetUserByIdAsync(command.UserId); if (user.SelectedTenantId == command.SelectedTenantId) { @@ -28,7 +24,7 @@ public async Task HandleAsync(SetSelectedTenantForUser command, CancellationToke user.SelectedTenantId = command.SelectedTenantId; - await tenantIdentityDbContext.SaveChangesAsync(cancellationToken); + await module.TenantIdentityDbContext.SaveChangesAsync(cancellationToken); } } } diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetClaimsForUser.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetClaimsForUser.cs index 58e13aa9..66b364c8 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetClaimsForUser.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetClaimsForUser.cs @@ -1,5 +1,4 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Query; +using Shared.Features.Messaging.Query; using Shared.Features.Server; using Shared.Kernel.BuildingBlocks.Auth.Constants; using System.Security.Claims; @@ -14,11 +13,7 @@ public class GetClaimsForUser : IQuery> public class ClaimsForUserQueryHandler : ServerExecutionBase, IQueryHandler> { - - public ClaimsForUserQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) - { - - } + public ClaimsForUserQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task> HandleAsync(GetClaimsForUser query, CancellationToken cancellation) { diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetUserById.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetUserById.cs index 5d3f216f..cd52ad50 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetUserById.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/UserAggregate/Application/Queries/GetUserById.cs @@ -1,5 +1,5 @@ -using Modules.TenantIdentity.Features.Infrastructure.EFCore; -using Shared.Features.Messaging.Query; +using Shared.Features.Messaging.Query; +using Shared.Features.Server; using System.Threading; namespace Modules.TenantIdentity.Features.DomainFeatures.UserAggregate.Application.Queries @@ -8,17 +8,13 @@ public class GetUserById : IQuery { public Guid UserId { get; set; } } - public class GetUserByIdHandler : IQueryHandler + public class GetUserByIdHandler : ServerExecutionBase, IQueryHandler { - private readonly TenantIdentityDbContext tenantIdentityDbContext; - public GetUserByIdHandler(TenantIdentityDbContext tenantIdentityDbContext) - { - this.tenantIdentityDbContext = tenantIdentityDbContext; - } + public GetUserByIdHandler(IServiceProvider serviceProvider) : base(serviceProvider) { } public async Task HandleAsync(GetUserById query, CancellationToken cancellation) { - return await tenantIdentityDbContext.GetUserByIdAsync(query.UserId); + return await module.TenantIdentityDbContext.GetUserByIdAsync(query.UserId); } } } diff --git a/Source/Modules/TenantIdentity/Features/TenantIdentityModule.cs b/Source/Modules/TenantIdentity/Features/TenantIdentityModule.cs index afd6caf3..05289e35 100644 --- a/Source/Modules/TenantIdentity/Features/TenantIdentityModule.cs +++ b/Source/Modules/TenantIdentity/Features/TenantIdentityModule.cs @@ -1,12 +1,7 @@ using Modules.TenantIdentity.Features.Infrastructure.Configuration; using Modules.TenantIdentity.Features.Infrastructure.EFCore; using Shared.Features.Modules; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace Modules.TenantIdentity.Features { diff --git a/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs b/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs index f61b3641..0292c212 100644 --- a/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs +++ b/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs @@ -15,7 +15,6 @@ using System; using System.Threading.Tasks; using Modules.TenantIdentity.Features.Infrastructure.Configuration; -using System.Reflection; using Modules.TenantIdentity.Features.DomainFeatures.UserAggregate; using Shared.Features.EFCore; using Shared.Features.Modules.Configuration; diff --git a/Source/Shared/Features/Server/ServerExecutionBase.cs b/Source/Shared/Features/Server/ServerExecutionBase.cs index ba6b1e11..bf162442 100644 --- a/Source/Shared/Features/Server/ServerExecutionBase.cs +++ b/Source/Shared/Features/Server/ServerExecutionBase.cs @@ -1,5 +1,4 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Shared.Features.Messaging.Command; using Shared.Features.Messaging.DomainEvent; using Shared.Features.Messaging.IntegrationEvent;