/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public CSharpModelGenerator( ModelCodeGeneratorDependencies dependencies, ICSharpDbContextGenerator cSharpDbContextGenerator, ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(dependencies) { CSharpDbContextGenerator = cSharpDbContextGenerator; CSharpEntityTypeGenerator = cSharpEntityTypeGenerator; }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public CSharpScaffoldingGenerator( [NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator, [NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) { Check.NotNull(cSharpDbContextGenerator, nameof(cSharpDbContextGenerator)); Check.NotNull(cSharpEntityTypeGenerator, nameof(cSharpEntityTypeGenerator)); CSharpDbContextGenerator = cSharpDbContextGenerator; CSharpEntityTypeGenerator = cSharpEntityTypeGenerator; }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public CSharpScaffoldingGenerator( [NotNull] IFileService fileService, [NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator, [NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(fileService) { Check.NotNull(cSharpDbContextGenerator, nameof(cSharpDbContextGenerator)); Check.NotNull(cSharpEntityTypeGenerator, nameof(cSharpEntityTypeGenerator)); CSharpDbContextGenerator = cSharpDbContextGenerator; CSharpEntityTypeGenerator = cSharpEntityTypeGenerator; }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public CSharpModelGenerator( [NotNull] ModelCodeGeneratorDependencies dependencies, [NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator, [NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(dependencies) { Check.NotNull(cSharpDbContextGenerator, nameof(cSharpDbContextGenerator)); Check.NotNull(cSharpEntityTypeGenerator, nameof(cSharpEntityTypeGenerator)); CSharpDbContextGenerator = cSharpDbContextGenerator; CSharpEntityTypeGenerator = cSharpEntityTypeGenerator; }
public ModelGenerator( IOptions <DbContextOptions> dbContextOptionsAccessor, IOptions <ScaffoldingOptions> scaffoldingOptionsAccessor, ICSharpDbContextGenerator dbContextGenerator, ICSharpEntityTypeGenerator entityTypeGenerator ) { this.dbContextOptions = dbContextOptionsAccessor.Value; this.scaffoldingOptions = scaffoldingOptionsAccessor.Value; this.dbContextGenerator = dbContextGenerator; this.entityTypeGenerator = entityTypeGenerator; }
/// <summary> /// Constructor for the Handlebars scaffolding generator. /// </summary> /// <param name="fileService">Provides files to the template service.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="entityTypeTemplateService">Template service for the entity types generator.</param> /// <param name="cSharpDbContextGenerator">DbContext generator.</param> /// <param name="cSharpEntityTypeGenerator">Entity types generator.</param> public HbsCSharpScaffoldingGenerator( ITemplateFileService fileService, IDbContextTemplateService dbContextTemplateService, IEntityTypeTemplateService entityTypeTemplateService, ICSharpDbContextGenerator cSharpDbContextGenerator, ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(fileService) { DbContextTemplateService = dbContextTemplateService ?? throw new ArgumentNullException(nameof(dbContextTemplateService)); EntityTypeTemplateService = entityTypeTemplateService ?? throw new ArgumentNullException(nameof(entityTypeTemplateService)); CSharpDbContextGenerator = cSharpDbContextGenerator ?? throw new ArgumentNullException(nameof(cSharpDbContextGenerator)); CSharpEntityTypeGenerator = cSharpEntityTypeGenerator ?? throw new ArgumentNullException(nameof(cSharpEntityTypeGenerator)); }
/// <summary> /// Constructor for the HbsCSharpModelGenerator. /// </summary> /// <param name="dependencies">Service dependencies parameter class for HbsCSharpModelGenerator.</param> /// <param name="handlebarsHelperService">Handlebars helper service.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="entityTypeTemplateService">Template service for the entity types generator.</param> /// <param name="cSharpDbContextGenerator">DbContext generator.</param> /// <param name="cSharpEntityTypeGenerator">Entity type generator.</param> public HbsCSharpModelGenerator(ModelCodeGeneratorDependencies dependencies, IHbsHelperService handlebarsHelperService, IDbContextTemplateService dbContextTemplateService, IEntityTypeTemplateService entityTypeTemplateService, ICSharpDbContextGenerator cSharpDbContextGenerator, ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(dependencies) { HandlebarsHelperService = handlebarsHelperService ?? throw new ArgumentNullException(nameof(handlebarsHelperService)); DbContextTemplateService = dbContextTemplateService ?? throw new ArgumentNullException(nameof(dbContextTemplateService)); EntityTypeTemplateService = entityTypeTemplateService ?? throw new ArgumentNullException(nameof(entityTypeTemplateService)); CSharpDbContextGenerator = cSharpDbContextGenerator ?? throw new ArgumentNullException(nameof(cSharpDbContextGenerator)); CSharpEntityTypeGenerator = cSharpEntityTypeGenerator ?? throw new ArgumentNullException(nameof(cSharpEntityTypeGenerator)); }
/// <summary> /// Constructor for the HbsTypeScriptModelGenerator. /// </summary> /// <param name="dependencies">Service dependencies parameter class for HbsCSharpModelGenerator.</param> /// <param name="cSharpDbContextGenerator">DbContext generator.</param> /// <param name="cSharpEntityTypeGenerator">Entity type generator.</param> /// <param name="handlebarsHelperService"></param> /// <param name="handlebarsBlockHelperService"></param> /// <param name="dbContextTemplateService"></param> /// <param name="entityTypeTemplateService"></param> /// <param name="entityTypeTransformationService"></param> public HbsTypeScriptModelGenerator( [NotNull] ModelCodeGeneratorDependencies dependencies, [NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator, [NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator, [NotNull] IHbsHelperService handlebarsHelperService, [NotNull] IHbsBlockHelperService handlebarsBlockHelperService, [NotNull] IDbContextTemplateService dbContextTemplateService, [NotNull] IEntityTypeTemplateService entityTypeTemplateService, [NotNull] IEntityTypeTransformationService entityTypeTransformationService) : base(dependencies, cSharpDbContextGenerator, cSharpEntityTypeGenerator) { HandlebarsHelperService = handlebarsHelperService; HandlebarsBlockHelperService = handlebarsBlockHelperService; DbContextTemplateService = dbContextTemplateService; EntityTypeTemplateService = entityTypeTemplateService; EntityTypeTransformationService = entityTypeTransformationService; }
/// <summary> /// Constructor for the HbsCSharpModelGenerator. /// </summary> /// <param name="dependencies">Service dependencies parameter class for HbsCSharpModelGenerator.</param> /// <param name="cSharpDbContextGenerator">DbContext generator.</param> /// <param name="cSharpEntityTypeGenerator">Entity type generator.</param> /// <param name="handlebarsHelperService">Handlebars helper service.</param> /// <param name="handlebarsBlockHelperService">Handlebars block helper service.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="entityTypeTemplateService">Template service for the entity types generator.</param> /// <param name="entityTypeTransformationService">Service for transforming entity definitions.</param> /// <param name="options">Handlebar scaffolding options</param> public HbsCSharpModelGenerator( [NotNull] ModelCodeGeneratorDependencies dependencies, [NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator, [NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator, [NotNull] IHbsHelperService handlebarsHelperService, [NotNull] IHbsBlockHelperService handlebarsBlockHelperService, [NotNull] IDbContextTemplateService dbContextTemplateService, [NotNull] IEntityTypeTemplateService entityTypeTemplateService, [NotNull] IEntityTypeTransformationService entityTypeTransformationService, [NotNull] IOptions <HandlebarsScaffoldingOptions> options) : base(dependencies, cSharpDbContextGenerator, cSharpEntityTypeGenerator) { HandlebarsHelperService = handlebarsHelperService; HandlebarsBlockHelperService = handlebarsBlockHelperService; DbContextTemplateService = dbContextTemplateService; EntityTypeTemplateService = entityTypeTemplateService; EntityTypeTransformationService = entityTypeTransformationService; _options = options; }
/// <summary> /// Constructor for the HbsCSharpModelGenerator. /// </summary> /// <param name="dependencies">Service dependencies parameter class for HbsCSharpModelGenerator.</param> /// <param name="handlebarsHelperService">Handlebars helper service.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="entityTypeTemplateService">Template service for the entity types generator.</param> /// <param name="entityTypeTransformationService">Service for transforming entity definitions.</param> /// <param name="cSharpDbContextGenerator">DbContext generator.</param> /// <param name="cSharpEntityTypeGenerator">Entity type generator.</param> public HbsCSharpModelGeneratorEnhance(ModelCodeGeneratorDependencies dependencies, IHbsHelperService handlebarsHelperService, IDbContextTemplateService dbContextTemplateService, IEntityTypeTemplateService entityTypeTemplateService, IEntityTypeConfigurationTemplateService entityTypeConfigurationTemplateService, IEntityTypeTransformationService entityTypeTransformationService, ICSharpDbContextGenerator cSharpDbContextGenerator, ICSharpEntityTypeGenerator cSharpEntityTypeGenerator, ICSharpEntityTypeConfigurationGenerator cSharpEntityTypeConfigurationGenerator, HandlebarsScaffoldingOptions handlebarsScaffoldingOptions) : base(dependencies, handlebarsHelperService, dbContextTemplateService, entityTypeTemplateService, entityTypeTransformationService, cSharpDbContextGenerator, cSharpEntityTypeGenerator) { EntityTypeConfigurationTemplateService = entityTypeConfigurationTemplateService; CSharpEntityTypeConfigurationGenerator = cSharpEntityTypeConfigurationGenerator; HandlebarsScaffoldingOptions = handlebarsScaffoldingOptions ?? HandlebarsScaffoldingOptions.Default; }
private Dictionary <string, string> ReverseEngineerFiles(ReverseEngineerOptions options, bool useDataAnnotations) { var fileService = new InMemoryTemplateFileService(); fileService.InputFiles(ContextClassTemplate, ContextImportsTemplate, ContextDbSetsTemplate, EntityClassTemplate, EntityImportsTemplate, EntityCtorTemplate, EntityPropertiesTemplate); var dbContextTemplateService = new HbsDbContextTemplateService(fileService); var entityTypeTemplateService = new HbsEntityTypeTemplateService(fileService); ICSharpUtilities cSharpUtilities = new CSharpUtilities(); ICSharpDbContextGenerator realContextGenerator = new HbsCSharpDbContextGenerator( new SqlServerScaffoldingCodeGenerator(), new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()), cSharpUtilities, new HbsDbContextTemplateService(fileService)); ICSharpDbContextGenerator contextGenerator = options == ReverseEngineerOptions.DbContextOnly || options == ReverseEngineerOptions.DbContextOnly ? realContextGenerator : new NullCSharpDbContextGenerator(); ICSharpEntityTypeGenerator realEntityGenerator = new HbsCSharpEntityTypeGenerator( cSharpUtilities, new HbsEntityTypeTemplateService(fileService)); ICSharpEntityTypeGenerator entityGenerator = options == ReverseEngineerOptions.EntitiesOnly || options == ReverseEngineerOptions.DbContextAndEntities ? realEntityGenerator : new NullCSharpEntityTypeGenerator(); IScaffoldingCodeGenerator scaffoldingGenerator = new HbsCSharpScaffoldingGenerator( fileService, dbContextTemplateService, entityTypeTemplateService, contextGenerator, entityGenerator); var modelFactory = new SqlServerDatabaseModelFactory( new DiagnosticsLogger <DbLoggerCategory.Scaffolding>( new TestSqlLoggerFactory(), new LoggingOptions(), new DiagnosticListener("Fake"))); var reverseEngineer = new ReverseEngineerScaffolder( modelFactory, new FakeScaffoldingModelFactory(new TestOperationReporter()), scaffoldingGenerator, cSharpUtilities); // Act var files = reverseEngineer.Generate( connectionString: Constants.Connections.SqlServerConnection, tables: Enumerable.Empty <string>(), schemas: Enumerable.Empty <string>(), projectPath: Constants.Parameters.ProjectPath, outputPath: null, rootNamespace: Constants.Parameters.RootNamespace, contextName: Constants.Parameters.ContextName, useDataAnnotations: useDataAnnotations, overwriteFiles: false, useDatabaseNames: false); var generatedFiles = new Dictionary <string, string>(); if (options == ReverseEngineerOptions.DbContextOnly || options == ReverseEngineerOptions.DbContextAndEntities) { var contextPath = files.ContextFile; var context = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(contextPath), Path.GetFileName(contextPath)); generatedFiles.Add(Constants.Files.DbContextFile, context); } if (options == ReverseEngineerOptions.EntitiesOnly || options == ReverseEngineerOptions.DbContextAndEntities) { var categoryPath = files.EntityTypeFiles[0]; var category = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(categoryPath), Path.GetFileName(categoryPath)); var productPath = files.EntityTypeFiles[1]; var product = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(productPath), Path.GetFileName(productPath)); generatedFiles.Add(Constants.Files.CategoryFile, category); generatedFiles.Add(Constants.Files.ProductFile, product); } return(generatedFiles); }
public MyCSharpScaffoldingGenerator(IFileService fileService, ICSharpDbContextGenerator cSharpDbContextGenerator, ICSharpEntityTypeGenerator cSharpEntityTypeGenerator) : base(fileService, cSharpDbContextGenerator, cSharpEntityTypeGenerator) { //BaseClassGenerator = baseClassGenerator; }