@ -19,22 +19,32 @@ namespace Volo.Abp.Cli.ProjectModification
protected IJsonSerializer JsonSerializer { get ; }
protected IJsonSerializer JsonSerializer { get ; }
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get ; }
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get ; }
protected DbContextFileBuilderConfigureAdder DbContextFileBuilderConfigureAdder { get ; }
protected EfCoreMigrationAdder EfCoreMigrationAdder { get ; }
protected ProjectNpmPackageAdder ProjectNpmPackageAdder { get ; }
protected ProjectNpmPackageAdder ProjectNpmPackageAdder { get ; }
protected DerivedClassFinder DerivedClassFinder { get ; }
public SolutionModuleAdder (
public SolutionModuleAdder (
IJsonSerializer jsonSerializer ,
IJsonSerializer jsonSerializer ,
ProjectNugetPackageAdder projectNugetPackageAdder ,
ProjectNugetPackageAdder projectNugetPackageAdder ,
DbContextFileBuilderConfigureAdder dbContextFileBuilderConfigureAdder ,
EfCoreMigrationAdder efCoreMigrationAdder ,
DerivedClassFinder derivedClassFinder ,
ProjectNpmPackageAdder projectNpmPackageAdder )
ProjectNpmPackageAdder projectNpmPackageAdder )
{
{
EfCoreMigrationAdder = efCoreMigrationAdder ;
DerivedClassFinder = derivedClassFinder ;
JsonSerializer = jsonSerializer ;
JsonSerializer = jsonSerializer ;
ProjectNugetPackageAdder = projectNugetPackageAdder ;
ProjectNugetPackageAdder = projectNugetPackageAdder ;
DbContextFileBuilderConfigureAdder = dbContextFileBuilderConfigureAdder ;
ProjectNpmPackageAdder = projectNpmPackageAdder ;
ProjectNpmPackageAdder = projectNpmPackageAdder ;
Logger = NullLogger < SolutionModuleAdder > . Instance ;
Logger = NullLogger < SolutionModuleAdder > . Instance ;
}
}
public virtual async Task AddAsync (
public virtual async Task AddAsync (
[NotNull] string solutionFile ,
[NotNull] string solutionFile ,
[NotNull] string moduleName )
[NotNull] string moduleName ,
bool skipDbMigrations = false )
{
{
Check . NotNull ( solutionFile , nameof ( solutionFile ) ) ;
Check . NotNull ( solutionFile , nameof ( solutionFile ) ) ;
Check . NotNull ( moduleName , nameof ( moduleName ) ) ;
Check . NotNull ( moduleName , nameof ( moduleName ) ) ;
@ -75,8 +85,42 @@ namespace Volo.Abp.Cli.ProjectModification
Logger . LogDebug ( "Target project is not available for NPM packages." ) ;
Logger . LogDebug ( "Target project is not available for NPM packages." ) ;
}
}
}
}
ModifyDbContext ( projectFiles , module , skipDbMigrations ) ;
}
protected void ModifyDbContext ( string [ ] projectFiles , ModuleInfo module , bool skipDbMigrations = false )
{
if ( string . IsNullOrWhiteSpace ( module . EfCoreConfigureMethodName ) )
{
return ;
}
var dbMigrationsProject = projectFiles . FirstOrDefault ( p = > p . EndsWith ( ".DbMigrations.csproj" ) ) ;
if ( dbMigrationsProject = = null )
{
Logger . LogDebug ( "Solution doesn't have a \".DbMigrations\" project." ) ;
return ;
}
var dbContextFile = DerivedClassFinder . Find ( dbMigrationsProject , "AbpDbContext" ) . FirstOrDefault ( ) ;
if ( dbContextFile = = null )
{
Logger . LogDebug ( $"{dbMigrationsProject} project doesn't have a class that is derived from \" AbpDbContext \ "." ) ;
return ;
}
DbContextFileBuilderConfigureAdder . Add ( dbContextFile , module . EfCoreConfigureMethodName ) ;
if ( ! skipDbMigrations )
{
EfCoreMigrationAdder . AddMigration ( dbMigrationsProject , module . Name ) ;
}
}
}
protected virtual async Task < ModuleInfo > FindModuleInfoAsync ( string moduleName )
protected virtual async Task < ModuleInfo > FindModuleInfoAsync ( string moduleName )
{
{
using ( var client = new HttpClient ( ) )
using ( var client = new HttpClient ( ) )