diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/AddMessageToChannelCommand.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/AddMessageToChannelCommand.cs index 11c686f3..bf073fb7 100644 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/AddMessageToChannelCommand.cs +++ b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/AddMessageToChannelCommand.cs @@ -11,8 +11,8 @@ public class AddMessageToChannelCommand : ICommand } public class AddMessageToChannelCommandHandler : ICommandHandler { - private readonly ChannelDbContext applicationDbContext; - public AddMessageToChannelCommandHandler(ChannelDbContext applicationDbContext) + private readonly ChannelsDbContext applicationDbContext; + public AddMessageToChannelCommandHandler(ChannelsDbContext applicationDbContext) { this.applicationDbContext = applicationDbContext; } diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/ChangeChannelNameCommand.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/ChangeChannelNameCommand.cs index 09fbd288..3b9ef004 100644 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/ChangeChannelNameCommand.cs +++ b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/ChangeChannelNameCommand.cs @@ -11,8 +11,8 @@ public class ChangeChannelNameCommand : ICommand public class ChangeChannelNameCommandHandler : ICommandHandler { - private readonly ChannelDbContext applicationDbContext; - public ChangeChannelNameCommandHandler(ChannelDbContext applicationDbContext) + private readonly ChannelsDbContext applicationDbContext; + public ChangeChannelNameCommandHandler(ChannelsDbContext applicationDbContext) { this.applicationDbContext = applicationDbContext; } diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/CreateChannelCommand.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/CreateChannelCommand.cs index 104eb8bd..2cba483e 100644 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/CreateChannelCommand.cs +++ b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/CreateChannelCommand.cs @@ -11,9 +11,9 @@ public class CreateChannelCommand : ICommand } public class CreateChannelCommandHandler : ICommandHandler { - private readonly ChannelDbContext applicationDbContext; + private readonly ChannelsDbContext applicationDbContext; private readonly ITenantResolver teamResolver; - public CreateChannelCommandHandler(ChannelDbContext applicationDbContext, ITenantResolver teamResolver) + public CreateChannelCommandHandler(ChannelsDbContext applicationDbContext, ITenantResolver teamResolver) { this.applicationDbContext = applicationDbContext; this.teamResolver = teamResolver; diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/DeleteChannelCommand.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/DeleteChannelCommand.cs index 4b9853f4..a73c6c68 100644 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/DeleteChannelCommand.cs +++ b/Source/Modules/Channels/Features/ChannelAggregate/Application/Commands/DeleteChannelCommand.cs @@ -10,9 +10,9 @@ public class DeleteChannelCommand : ICommand } public class DeleteChannelCommandCommandHandler : ICommandHandler { - private readonly ChannelDbContext applicationDbContext; + private readonly ChannelsDbContext applicationDbContext; private readonly ITenantResolver teamResolver; - public DeleteChannelCommandCommandHandler(ChannelDbContext applicationDbContext, ITenantResolver teamResolver) + public DeleteChannelCommandCommandHandler(ChannelsDbContext applicationDbContext, ITenantResolver teamResolver) { this.applicationDbContext = applicationDbContext; this.teamResolver = teamResolver; diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/EventHandlers/ChannelMessagesUpdatedEventHandler.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/EventHandlers/ChannelMessagesUpdatedEventHandler.cs index 79719430..445cb4bc 100644 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/EventHandlers/ChannelMessagesUpdatedEventHandler.cs +++ b/Source/Modules/Channels/Features/ChannelAggregate/Application/EventHandlers/ChannelMessagesUpdatedEventHandler.cs @@ -1,4 +1,5 @@ using Modules.Channels.Features.ChannelAggregate.Events; +using Shared.Features.CQRS.DomainEvent; namespace Modules.Channels.Features.ChannelAggregate.Application.EventHandlers { diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/GlobalUsings.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/GlobalUsings.cs deleted file mode 100644 index 5f282702..00000000 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/IAssemblyMarker.cs b/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/IAssemblyMarker.cs deleted file mode 100644 index 1cf790ee..00000000 --- a/Source/Modules/Channels/Features/ChannelAggregate/Application/Misc/IAssemblyMarker.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Modules.Channels.Features.ChannelAggregate.Application.Misc -{ - public interface IAssemblyMarker - { - } -} diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Misc/GlobalUsings.cs b/Source/Modules/Channels/Features/ChannelAggregate/Misc/GlobalUsings.cs deleted file mode 100644 index 5f282702..00000000 --- a/Source/Modules/Channels/Features/ChannelAggregate/Misc/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Source/Modules/Channels/Features/ChannelAggregate/Misc/IAssemblyMarker.cs b/Source/Modules/Channels/Features/ChannelAggregate/Misc/IAssemblyMarker.cs deleted file mode 100644 index 7dc26547..00000000 --- a/Source/Modules/Channels/Features/ChannelAggregate/Misc/IAssemblyMarker.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Modules.Channels.Features.ChannelAggregate.Misc -{ - public interface IAssemblyMarker - { - } -} diff --git a/Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelDbContext.cs b/Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelsDbContext.cs similarity index 50% rename from Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelDbContext.cs rename to Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelsDbContext.cs index 0408bd7e..ab654bf4 100644 --- a/Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelDbContext.cs +++ b/Source/Modules/Channels/Features/Infrastructure/EFCore/ChannelsDbContext.cs @@ -4,9 +4,9 @@ namespace Modules.Channels.Features.Infrastructure.EFCore { - public class ChannelDbContext : BaseDbContext + public class ChannelsDbContext : BaseDbContext { - public ChannelDbContext(DbContextOptions dbContextOptions, IServiceProvider serviceProvider, IConfiguration configuration) : base(dbContextOptions, serviceProvider, configuration) + public ChannelsDbContext(DbContextOptions dbContextOptions, IServiceProvider serviceProvider, IConfiguration configuration) : base(dbContextOptions, serviceProvider, configuration) { } diff --git a/Source/Modules/Channels/Web/Server/ChannelsModuleStartup.cs b/Source/Modules/Channels/Web/Server/ChannelsModuleStartup.cs new file mode 100644 index 00000000..6a9eeded --- /dev/null +++ b/Source/Modules/Channels/Web/Server/ChannelsModuleStartup.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Modules.Channels.Features.Infrastructure.EFCore; +using Shared.Features.Modules; +using System.Reflection; +using Shared.Features.EFCore; + +namespace Modules.Channels.Web.Server +{ + public class ChannelsModuleStartup : IModuleStartup + { + public Assembly FeaturesAssembly { get; } = typeof(ChannelsModuleStartup).Assembly; + public void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + services.AddControllers().AddApplicationPart(typeof(ChannelsModuleStartup).Assembly); + services.AddSignalR(); + + services.RegisterDbContext("Contacts"); + } + + public void Configure(IApplicationBuilder app, IHostEnvironment env) + { + + } + } +} diff --git a/Source/Modules/Channels/Web/Server/Modules.Channels.Web.Server.csproj b/Source/Modules/Channels/Web/Server/Modules.Channels.Web.Server.csproj index 3a6446cf..6cdfb87f 100644 --- a/Source/Modules/Channels/Web/Server/Modules.Channels.Web.Server.csproj +++ b/Source/Modules/Channels/Web/Server/Modules.Channels.Web.Server.csproj @@ -18,7 +18,6 @@ - diff --git a/Source/Modules/LandingPages/Web/Server/LandingPagesModuleServerRegistrator.cs b/Source/Modules/LandingPages/Web/Server/LandingPagesModuleServerRegistrator.cs deleted file mode 100644 index f4174643..00000000 --- a/Source/Modules/LandingPages/Web/Server/LandingPagesModuleServerRegistrator.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LandingPagesModule.Server -{ - internal class LandingPagesModuleServerRegistrator - { - } -} diff --git a/Source/Modules/LandingPages/Web/Server/LandingPagesModuleStartup.cs b/Source/Modules/LandingPages/Web/Server/LandingPagesModuleStartup.cs new file mode 100644 index 00000000..298ab404 --- /dev/null +++ b/Source/Modules/LandingPages/Web/Server/LandingPagesModuleStartup.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +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.LandingPages.Server +{ + public class LandingPagesModuleStartup : IModuleStartup + { + public Assembly FeaturesAssembly { get; } = typeof(LandingPagesModuleStartup).Assembly; + public void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + services.AddRazorPages() + .AddApplicationPart(typeof(LandingPagesModuleStartup).Assembly); + } + + public void Configure(IApplicationBuilder app, IHostEnvironment env) + { + + } + } +} diff --git a/Source/Modules/LandingPages/Web/Server/Modules.LandingPages.Server.csproj b/Source/Modules/LandingPages/Web/Server/Modules.LandingPages.Server.csproj index 014cf8b0..c14dd6d2 100644 --- a/Source/Modules/LandingPages/Web/Server/Modules.LandingPages.Server.csproj +++ b/Source/Modules/LandingPages/Web/Server/Modules.LandingPages.Server.csproj @@ -12,6 +12,10 @@ + + + + diff --git a/Source/Modules/Subscription/Web/Server/StripeSessionController.cs b/Source/Modules/Subscription/Web/Server/Controllers/StripeSessionController.cs similarity index 97% rename from Source/Modules/Subscription/Web/Server/StripeSessionController.cs rename to Source/Modules/Subscription/Web/Server/Controllers/StripeSessionController.cs index 00524068..4f555f8c 100644 --- a/Source/Modules/Subscription/Web/Server/StripeSessionController.cs +++ b/Source/Modules/Subscription/Web/Server/Controllers/StripeSessionController.cs @@ -1,4 +1,4 @@ -namespace WebServer.Controllers.Stripe +namespace Modules.Subscriptions.Web.Server.Controllers { [Route("api/[controller]")] [ApiController] diff --git a/Source/Modules/Subscription/Web/Server/StripeSuccessController.cs b/Source/Modules/Subscription/Web/Server/Controllers/StripeSuccessController.cs similarity index 100% rename from Source/Modules/Subscription/Web/Server/StripeSuccessController.cs rename to Source/Modules/Subscription/Web/Server/Controllers/StripeSuccessController.cs diff --git a/Source/Modules/Subscription/Web/Server/StripeWebhook.cs b/Source/Modules/Subscription/Web/Server/Controllers/StripeWebhook.cs similarity index 100% rename from Source/Modules/Subscription/Web/Server/StripeWebhook.cs rename to Source/Modules/Subscription/Web/Server/Controllers/StripeWebhook.cs diff --git a/Source/Modules/Subscription/Web/Server/Modules.Subscriptions.Web.Server.csproj b/Source/Modules/Subscription/Web/Server/Modules.Subscriptions.Web.Server.csproj index 71dd1f30..057bf71e 100644 --- a/Source/Modules/Subscription/Web/Server/Modules.Subscriptions.Web.Server.csproj +++ b/Source/Modules/Subscription/Web/Server/Modules.Subscriptions.Web.Server.csproj @@ -12,7 +12,8 @@ - + + diff --git a/Source/Modules/Subscription/Web/Server/SubscriptionModuleServerRegistrator.cs b/Source/Modules/Subscription/Web/Server/SubscriptionModuleServerRegistrator.cs deleted file mode 100644 index b4df8893..00000000 --- a/Source/Modules/Subscription/Web/Server/SubscriptionModuleServerRegistrator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Stripe; - -namespace Shared.Modules.Layers.Features.StripeIntegration -{ - public static class StripeDIRegistrator - { - public static IServiceCollection RegisterStripe(this IServiceCollection services, IConfiguration configuration) - { - StripeConfiguration.ApiKey = configuration["Stripe:StripeKey"]; - services.Configure(configuration); - services.AddScoped(); - - return services; - } - } -} diff --git a/Source/Modules/Subscription/Web/Server/SubscriptionsModuleStartup.cs b/Source/Modules/Subscription/Web/Server/SubscriptionsModuleStartup.cs new file mode 100644 index 00000000..e9df1a86 --- /dev/null +++ b/Source/Modules/Subscription/Web/Server/SubscriptionsModuleStartup.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Shared.Features.Modules; +using Stripe; +using System.Reflection; + +namespace Modules.Subscriptions.Web.Server +{ + public class SubscriptionsModuleStartup : IModuleStartup + { + public Assembly FeaturesAssembly { get; } = typeof(SubscriptionsModuleStartup).Assembly; + public void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + StripeConfiguration.ApiKey = configuration["Stripe:StripeKey"]; + //services.Configure(configuration); + //services.AddScoped(); + + services.AddControllers() + .AddApplicationPart(typeof(SubscriptionsModuleStartup).Assembly); + } + + public void Configure(IApplicationBuilder app, IHostEnvironment env) + { + + } + } +} diff --git a/Source/Modules/TenantIdentity/Web/Server/Modules.TenantIdentity.Web.Server.csproj b/Source/Modules/TenantIdentity/Web/Server/Modules.TenantIdentity.Web.Server.csproj index 104b0ed1..2c814f55 100644 --- a/Source/Modules/TenantIdentity/Web/Server/Modules.TenantIdentity.Web.Server.csproj +++ b/Source/Modules/TenantIdentity/Web/Server/Modules.TenantIdentity.Web.Server.csproj @@ -23,7 +23,6 @@ - diff --git a/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleRegistrator.cs b/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs similarity index 88% rename from Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleRegistrator.cs rename to Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs index 8aca7051..d59e70a8 100644 --- a/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleRegistrator.cs +++ b/Source/Modules/TenantIdentity/Web/Server/TenantIdentityModuleStartup.cs @@ -1,22 +1,30 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Shared.Features.Modules; using Shared.Kernel.BuildingBlocks.Authorization.Services; using Shared.SharedKernel.Constants; +using System.Reflection; using System.Security.Claims; -namespace Shared.Modules.Layers.Features.Identity +namespace Modules.TenantIdentity.Web.Server { - public static class TenantIdentityRegistrator + public class TenantIdentityModuleStartup : IModuleStartup { - public static IServiceCollection RegisterIdentity(this IServiceCollection services, IConfiguration configuration) + public Assembly FeaturesAssembly { get; } = typeof(TenantIdentityModuleStartup).Assembly; + public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { + services.AddControllers().AddApplicationPart(typeof(TenantIdentityModuleStartup).Assembly); + services.AddSignalR(); + services.AddSingleton(); //services.AddScoped(); @@ -109,8 +117,11 @@ public static IServiceCollection RegisterIdentity(this IServiceCollection servic .AddSignInManager(); services.AddScoped(); + } + + public void Configure(IApplicationBuilder app, IHostEnvironment env) + { - return services; } } } diff --git a/Source/Shared/Shared.Infrastructure/CQRS/CQRSDIRegistrator.cs b/Source/Shared/Shared.Infrastructure/CQRS/CQRSDIRegistrator.cs index d892a2c3..007590e8 100644 --- a/Source/Shared/Shared.Infrastructure/CQRS/CQRSDIRegistrator.cs +++ b/Source/Shared/Shared.Infrastructure/CQRS/CQRSDIRegistrator.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using System.Reflection; using Shared.Features.CQRS.Command; -using Shared.Features.CQRS.Features.DomainKernelEvent; namespace Shared.Features.CQRS { diff --git a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/DomainEventDispatcher.cs b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/DomainEventDispatcher.cs index 1fa13773..e16dd18d 100644 --- a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/DomainEventDispatcher.cs +++ b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/DomainEventDispatcher.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Shared.Features.DomainKernel.Interfaces; -namespace Shared.Features.CQRS.Features.DomainKernelEvent +namespace Shared.Features.CQRS.DomainEvent { public class DomainEventDispatcher : IDomainEventDispatcher { diff --git a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventDispatcher.cs b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventDispatcher.cs index cc1ba9b5..f705251c 100644 --- a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventDispatcher.cs +++ b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventDispatcher.cs @@ -1,6 +1,6 @@ using Shared.Features.DomainKernel.Interfaces; -namespace Shared.Features.CQRS.Features.DomainKernelEvent +namespace Shared.Features.CQRS.DomainEvent { public interface IDomainEventDispatcher { diff --git a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventHandler.cs b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventHandler.cs index 5a53caf6..9fb591f1 100644 --- a/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventHandler.cs +++ b/Source/Shared/Shared.Infrastructure/CQRS/DomainEvent/IDomainEventHandler.cs @@ -1,6 +1,6 @@ using Shared.Features.DomainKernel.Interfaces; -namespace Shared.Features.CQRS.Features.DomainKernelEvent +namespace Shared.Features.CQRS.DomainEvent { public interface IDomainEventHandler where TDomainEvent : IDomainEvent { diff --git a/Source/Shared/Shared.Infrastructure/EFCore/BaseDbContext.cs b/Source/Shared/Shared.Infrastructure/EFCore/BaseDbContext.cs index ef4a47fa..6720182e 100644 --- a/Source/Shared/Shared.Infrastructure/EFCore/BaseDbContext.cs +++ b/Source/Shared/Shared.Infrastructure/EFCore/BaseDbContext.cs @@ -4,7 +4,6 @@ using Shared.Features.DomainKernel; using Microsoft.EntityFrameworkCore.ChangeTracking; using Shared.Features.MultiTenancy.EFCore; -using Shared.Features.CQRS.Features.DomainKernelEvent; using Shared.Kernel.BuildingBlocks.Authorization.Services; namespace Shared.Features.EFCore diff --git a/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfiguration.cs b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfiguration.cs new file mode 100644 index 00000000..3c26d9f3 --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfiguration.cs @@ -0,0 +1,7 @@ +namespace Shared.Features.EFCore.Configuration +{ + public class EFCoreConfiguration + { + public string SQLServerConnectionString { get; set; } + } +} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationConstants.cs b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationConstants.cs new file mode 100644 index 00000000..d1dc6f2a --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationConstants.cs @@ -0,0 +1,8 @@ +namespace Shared.Features.EFCore.Configuration +{ + public class EFCoreConfigurationConstants + { + public const string DevelopmentSQLServerConnectionString = nameof(DevelopmentSQLServerConnectionString); + public const string ProductionSQLServerConnectionString = nameof(ProductionSQLServerConnectionString); + } +} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationRegistrator.cs b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationRegistrator.cs new file mode 100644 index 00000000..321929ae --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationRegistrator.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +namespace Shared.Features.EFCore.Configuration +{ + public static class EFCoreConfigurationRegistrator + { + public static IServiceCollection RegisterEFCore(this IServiceCollection services, IConfiguration configuration) + { + services.AddScoped(sp => + { + EFCoreConfiguration tc = new EFCoreConfiguration(); + configuration.GetSection(nameof(EFCoreConfiguration)).Bind(tc); + return tc; + }); + services.Configure(configuration.GetSection(nameof(EFCoreConfiguration))); + services.AddSingleton, EFCoreConfigurationValidator>(); + + return services; + } + } +} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationValidator.cs b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationValidator.cs new file mode 100644 index 00000000..ebb60aaa --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/EFCore/Configuration/EFCoreConfigurationValidator.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Options; + +namespace Shared.Features.EFCore.Configuration +{ + internal class EFCoreConfigurationValidator : IValidateOptions + { + public ValidateOptionsResult Validate(string name, EFCoreConfiguration efCoreConfiguration) + { + //if (string.IsNullOrEmpty(efCoreConfiguration.SQLServerConnectionString)) + //{ + // return ValidateOptionsResult.Fail(""); + //} + + return ValidateOptionsResult.Success; + } + } +} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/DbContextRegistrator.cs b/Source/Shared/Shared.Infrastructure/EFCore/DbContextRegistrator.cs new file mode 100644 index 00000000..fd03953c --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/EFCore/DbContextRegistrator.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Shared.Features.EFCore +{ + public static class DbContextRegistrator + { + public static void RegisterDbContext(this IServiceCollection services, string schemaName) where T : DbContext + { + var serviceProvider = services.BuildServiceProvider(); + + services.AddDbContext(options => + { + var connectionString = serviceProvider.GetRequiredService().SQLServerConnectionString; + + options.UseSqlServer(connectionString, sqlServerOptions => + { + sqlServerOptions.EnableRetryOnFailure(5); + sqlServerOptions.CommandTimeout(15); + sqlServerOptions.MigrationsHistoryTable($"{schemaName}_MigrationHistory"); + }); + }); + + if (serviceProvider.GetRequiredService().IsProduction()) + { + using (var scope = services.BuildServiceProvider().CreateScope()) + { + var db = scope.ServiceProvider.GetService(); + db.Database.Migrate(); + } + } + } + } +} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/EFCoreDIRegistrator.cs b/Source/Shared/Shared.Infrastructure/EFCore/EFCoreDIRegistrator.cs deleted file mode 100644 index 08c3a4c4..00000000 --- a/Source/Shared/Shared.Infrastructure/EFCore/EFCoreDIRegistrator.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace Shared.Features.EFCore -{ - public static class EFCoreDIRegistrator - { - public static IServiceCollection RegisterEFCore(this IServiceCollection services, IConfiguration configuration) - { - - return services; - } - } -} diff --git a/Source/Shared/Shared.Infrastructure/EFCore/Migrations/IMigrationAssemblyMarker.cs b/Source/Shared/Shared.Infrastructure/EFCore/Migrations/IMigrationAssemblyMarker.cs deleted file mode 100644 index 2127e271..00000000 --- a/Source/Shared/Shared.Infrastructure/EFCore/Migrations/IMigrationAssemblyMarker.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Shared.Features.EFCore.Migrations -{ - public interface IMigrationAssemblyMarker - { - } -} diff --git a/Source/Shared/Shared.Infrastructure/Modules/IModuleStartup.cs b/Source/Shared/Shared.Infrastructure/Modules/IModuleStartup.cs new file mode 100644 index 00000000..09430526 --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/Modules/IModuleStartup.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System.Reflection; + +namespace Shared.Features.Modules +{ + public interface IModuleStartup + { + public Assembly? FeaturesAssembly { get; } + void ConfigureServices(IServiceCollection services, IConfiguration configuration); + void Configure(IApplicationBuilder app, IHostEnvironment env); + } +} diff --git a/Source/Shared/Shared.Infrastructure/Modules/Module.cs b/Source/Shared/Shared.Infrastructure/Modules/Module.cs new file mode 100644 index 00000000..d4aa998e --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/Modules/Module.cs @@ -0,0 +1,22 @@ +using System.Reflection; + +namespace Shared.Features.Modules +{ + public class Module + { + /// + /// Gets the startup class of the module. + /// + public IModuleStartup Startup { get; } + + /// + /// Gets the assembly of the module. + /// + public Assembly Assembly => Startup.GetType().Assembly; + + public Module(IModuleStartup startup) + { + Startup = startup; + } + } +} diff --git a/Source/Shared/Shared.Infrastructure/Modules/ModuleRegistrator.cs b/Source/Shared/Shared.Infrastructure/Modules/ModuleRegistrator.cs new file mode 100644 index 00000000..346e4fc0 --- /dev/null +++ b/Source/Shared/Shared.Infrastructure/Modules/ModuleRegistrator.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Shared.Features.CQRS; + +namespace Shared.Features.Modules +{ + public static class ModuleRegistrator + { + public static IServiceCollection AddModule(this IServiceCollection services, IConfiguration configuration) + where TStartup : IModuleStartup, new() + { + // Register assembly in MVC so it can find controllers of the module + services.AddControllers().ConfigureApplicationPartManager(manager => + manager.ApplicationParts.Add(new AssemblyPart(typeof(TStartup).Assembly))); + + var startup = new TStartup(); + startup.ConfigureServices(services, configuration); + + services.AddSingleton(new Module(startup)); + + return services; + } + + public static void AddModules(this IServiceCollection services) + { + var serviceProvider = services.BuildServiceProvider(); + + var startupModules = serviceProvider.GetRequiredService>(); + + services.RegisterCQRS(startupModules.Where(sm => sm.Startup.FeaturesAssembly is not null).Select(sm => sm.Startup.FeaturesAssembly).ToArray()); + } + + public static IApplicationBuilder UseModules(this IApplicationBuilder app, IHostEnvironment env) + { + // Adds endpoints defined in modules + var modules = app + .ApplicationServices + .GetRequiredService>(); + foreach (var module in modules) + { + module.Startup.Configure(app, env); + } + + return app; + } + } +} diff --git a/Source/Shared/Shared.Infrastructure/Server/AuthenticatedBaseController.cs b/Source/Shared/Shared.Infrastructure/Server/AuthenticatedBaseController.cs index 676bb163..2465ec66 100644 --- a/Source/Shared/Shared.Infrastructure/Server/AuthenticatedBaseController.cs +++ b/Source/Shared/Shared.Infrastructure/Server/AuthenticatedBaseController.cs @@ -1,9 +1,28 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Shared.Features.CQRS.Command; +using Shared.Features.CQRS.Query; +using SharedKernel.Interfaces; -namespace BaseShared.Modules.Layers.Features.MVC +namespace Shared.Features.Server { - public class AuthenticatedBaseController : ControllerBase + public class BaseController : ControllerBase { + protected readonly ICommandDispatcher commandDispatcher; + protected readonly IQueryDispatcher queryDispatcher; + protected readonly IExecutionContextAccessor executionContextAccessor; + protected readonly IWebContextAccessor webContextAccessor; + protected readonly IValidationService validationService; + + public BaseController(IServiceProvider serviceProvider) + { + commandDispatcher = serviceProvider.GetRequiredService(); + queryDispatcher = serviceProvider.GetRequiredService(); + executionContextAccessor = serviceProvider.GetRequiredService(); + webContextAccessor = serviceProvider.GetService(); + validationService = serviceProvider.GetRequiredService(); + } + public async Task ActionResult() { diff --git a/Source/Shared/Shared.Infrastructure/Shared.Features.csproj b/Source/Shared/Shared.Infrastructure/Shared.Features.csproj index 1690c3d5..5cf9a0ff 100644 --- a/Source/Shared/Shared.Infrastructure/Shared.Features.csproj +++ b/Source/Shared/Shared.Infrastructure/Shared.Features.csproj @@ -8,13 +8,12 @@ - - + diff --git a/Source/Web/WebServer/Startup.cs b/Source/Web/WebServer/Startup.cs index 9959cdb5..6bafdef8 100644 --- a/Source/Web/WebServer/Startup.cs +++ b/Source/Web/WebServer/Startup.cs @@ -1,5 +1,4 @@ using Shared.Features.EmailSender; -using Shared.Features.EFCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; @@ -26,57 +25,7 @@ public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironm // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - #region Framework - services.AddRazorPages(options => - { - options.Conventions.AuthorizeFolder("/Identity/TeamManagement", "TeamAdmin"); - options.Conventions.AuthorizeFolder("/Identity"); - options.Conventions.AllowAnonymousToFolder("/LandingPages"); - options.Conventions.AllowAnonymousToFolder("/Identity/Stripe"); - options.Conventions.AllowAnonymousToPage("/Identity/Login"); - options.Conventions.AllowAnonymousToPage("/Identity/SignUp"); - options.Conventions.AllowAnonymousToPage("/Identity/TwoFactorLogin"); - options.Conventions.AllowAnonymousToPage("/Identity/LoginWithRecoveryCode"); - }); - - services.AddControllers(options => - { - //AuthorizeFilterBehaviour - options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()); - }) - .AddFluentValidation(options => - { - options.DisableDataAnnotationsValidation = true; - options.RegisterValidatorsFromAssembly(typeof(IAssemblyMarker).Assembly); - }) - .AddJsonOptions(options => - { - options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; - }); - #endregion - - #region Modules - services.RegisterModelValidation(); - services.RegisterAutoMapper(); - services.RegisterServerInformationProvider(); - services.RegisterSwagger(); - services.RegisterApiVersioning(); - #endregion - - #region Shared.Modules.Layers.Features - //services.RegisterCQRS(); - services.RegisterEmailSender(Configuration); - services.RegisterEFCore(Configuration); - services.RegisterMultiTenancy(); - services.RegisterRedisCache(Configuration); - //services.RegisterStripe(Configuration); - //services.RegisterIdentity(Configuration); - //services.RegisterSignalR(); - #endregion - - //services.RegisterChannelModuleServer(); - - services.RegisterAuthorization(); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Source/Web/WebServer/Web.Server.csproj b/Source/Web/WebServer/Web.Server.csproj index 7c0537dd..87fa8ca0 100644 --- a/Source/Web/WebServer/Web.Server.csproj +++ b/Source/Web/WebServer/Web.Server.csproj @@ -8,7 +8,7 @@ - +