diff --git a/modules/identity/src/Volo.Abp.Identity.Installer/Volo/Abp/Identity/IdentityInstallerPipelineBuilder.cs b/modules/identity/src/Volo.Abp.Identity.Installer/Volo/Abp/Identity/IdentityInstallerPipelineBuilder.cs index 2cf137d81e..8f2f75c30c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Installer/Volo/Abp/Identity/IdentityInstallerPipelineBuilder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Installer/Volo/Abp/Identity/IdentityInstallerPipelineBuilder.cs @@ -11,6 +11,13 @@ namespace Volo.Abp.Identity { public async Task BuildAsync(ModuleInstallingContext context) { + context.AddEfCoreConfigurationMethodDeclaration( + new EfCoreConfigurationMethodDeclaration( + "Volo.Abp.Identity.EntityFrameworkCore", + "ConfigureIdentity" + ) + ); + return GetBasePipeline(context); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs new file mode 100644 index 0000000000..5b69a49cbd --- /dev/null +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs @@ -0,0 +1,18 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.Studio.ModuleInstalling +{ + public class EfCoreConfigurationMethodDeclaration + { + public string Namespace { get; } + + public string MethodName { get; } + + public EfCoreConfigurationMethodDeclaration([NotNull] string nameSpace, [NotNull] string methodName) + { + Namespace = Check.NotNullOrEmpty(nameSpace, nameof(nameSpace)); + MethodName = Check.NotNullOrEmpty(methodName, nameof(methodName)); + } + + } +} diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs index b1ace699dc..ab5c142a50 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs @@ -18,6 +18,8 @@ namespace Volo.Abp.Studio.ModuleInstalling public string Version { get; set; } + public List EfCoreConfigurationMethodDeclarations { get; } + public List TargetModulePackages { get; protected set; } public List ReferenceModulePackages { get; protected set; } @@ -45,9 +47,21 @@ namespace Volo.Abp.Studio.ModuleInstalling TargetModulePackages = new List(); ReferenceModulePackages = new List(); + EfCoreConfigurationMethodDeclarations = new List(); + ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); } + public void AddEfCoreConfigurationMethodDeclaration(params EfCoreConfigurationMethodDeclaration[] methodNames) + { + foreach (var methodName in methodNames) + { + Check.NotNull(methodName, nameof(methodName)); + + EfCoreConfigurationMethodDeclarations.Add(methodName); + } + } + public void SetReferenceModulePackages([NotNull] List referenceModulePackages) { Check.NotNull(referenceModulePackages, nameof(referenceModulePackages)); diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs index 6443e39511..ba78031686 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs @@ -1,4 +1,5 @@ -using Volo.Abp.Studio.ModuleInstalling.Steps; +using System.Linq; +using Volo.Abp.Studio.ModuleInstalling.Steps; namespace Volo.Abp.Studio.ModuleInstalling { @@ -20,6 +21,11 @@ namespace Volo.Abp.Studio.ModuleInstalling pipeline.Add(new PackageReferencingStep()); + if (context.EfCoreConfigurationMethodDeclarations.Any()) + { + pipeline.Add(new AddEfCoreConfigurationMethodStep()); + } + return pipeline; } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs new file mode 100644 index 0000000000..54d6ec2cee --- /dev/null +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Cli.ProjectModification; +using Volo.Abp.Studio.Packages; +using Volo.Abp.Studio.Packages.Modifying; +using Volo.Abp.Studio.Analyzing.Models.Module; + +namespace Volo.Abp.Studio.ModuleInstalling.Steps +{ + public class AddEfCoreConfigurationMethodStep : ModuleInstallingPipelineStep + { + public override async Task ExecuteAsync(ModuleInstallingContext context) + { + var efCoreProject = context.TargetModulePackages.FirstOrDefault(p => p.Role == PackageTypes.EntityFrameworkCore); + + if (efCoreProject == null) + { + return; + } + + var efCoreProjectCsprojPath = efCoreProject.Path.RemovePostFix(PackageConsts.FileExtension) + ".csproj"; + + var _derivedClassFinder = context.ServiceProvider.GetRequiredService(); + var _dbContextFileBuilderConfigureAdder = context.ServiceProvider.GetRequiredService(); + + var dbContextFile = _derivedClassFinder.Find(efCoreProjectCsprojPath, "AbpDbContext").FirstOrDefault(); + + if (dbContextFile == null) + { + return; + } + + foreach (var declaration in context.EfCoreConfigurationMethodDeclarations) + { + _dbContextFileBuilderConfigureAdder.Add(dbContextFile, declaration.Namespace + ":" + declaration.MethodName); + } + } + } +}