Exemple #1
0
        private static void RunMicroTemplateBuilders(string solutionDirectory, List <Microservice> microservices, List <Gateway> gateways, IFileSystem fileSystem)
        {
            // services path
            var servicesPath = Path.Combine(solutionDirectory, "services");

            fileSystem.Directory.CreateDirectory(servicesPath);

            foreach (var micro in microservices)
            {
                // set micro path
                var microPath = Path.Combine(servicesPath, micro.ProjectFolderName);

                // add projects
                SolutionBuilder.AddMicroServicesProjects(solutionDirectory, microPath, micro.DbContext.Provider, micro.ProjectFolderName, micro.AddJwtAuthentication, fileSystem);

                // dbcontext
                DbContextBuilder.CreateDbContext(microPath, micro.Entities, micro.DbContext.ContextName, micro.DbContext.Provider, micro.DbContext.DatabaseName);

                //entities
                foreach (var entity in micro.Entities)
                {
                    EntityBuilder.CreateEntity(microPath, entity, fileSystem);
                    DtoBuilder.CreateDtos(microPath, entity);

                    RepositoryBuilder.AddRepository(microPath, entity, micro.DbContext);
                    ValidatorBuilder.CreateValidators(microPath, entity);
                    ProfileBuilder.CreateProfile(microPath, entity);

                    ControllerBuilder.CreateController(microPath, entity, micro.SwaggerConfig.AddSwaggerComments, micro.AuthorizationSettings.Policies);

                    FakesBuilder.CreateFakes(microPath, micro.ProjectFolderName, entity);
                    ReadTestBuilder.CreateEntityReadTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName);
                    GetTestBuilder.CreateEntityGetTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    PostTestBuilder.CreateEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.AuthorizationSettings.Policies);
                    UpdateTestBuilder.CreateEntityUpdateTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteIntegrationTestBuilder.CreateEntityDeleteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteTestBuilder.DeleteEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName);
                    WebAppFactoryBuilder.CreateWebAppFactory(microPath, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AddJwtAuthentication);
                }


                // environments
                Utilities.AddStartupEnvironmentsWithServices(
                    microPath,
                    micro.ProjectFolderName,
                    micro.DbContext.DatabaseName,
                    micro.Environments,
                    micro.SwaggerConfig,
                    micro.Port,
                    micro.AddJwtAuthentication
                    );

                //seeders
                SeederBuilder.AddSeeders(microPath, micro.Entities, micro.DbContext.ContextName);

                //services
                SwaggerBuilder.AddSwagger(microPath, micro.SwaggerConfig, micro.ProjectFolderName, micro.AddJwtAuthentication, micro.AuthorizationSettings.Policies);

                if (micro.AddJwtAuthentication)
                {
                    InfrastructureIdentityServiceRegistrationBuilder.CreateInfrastructureIdentityServiceExtension(microPath, micro.AuthorizationSettings.Policies, fileSystem);
                }
            }

            // gateway path
            var gatewayPath = Path.Combine(solutionDirectory, "gateways");

            fileSystem.Directory.CreateDirectory(gatewayPath);

            foreach (var gateway in gateways)
            {
                SolutionBuilder.AddGatewayProject(solutionDirectory, gatewayPath, gateway.GatewayProjectName, fileSystem);

                foreach (var env in gateway.EnvironmentGateways)
                {
                    //TODO: run quality checks that profile name exists, gateway url is a valid path and https, Env Name

                    if (env.EnvironmentName != "Startup")
                    {
                        StartupBuilder.CreateGatewayStartup(gatewayPath, env.EnvironmentName, gateway.GatewayProjectName);
                    }

                    GatewayAppSettingsBuilder.CreateAppSettings(gatewayPath, env, gateway.GatewayProjectName, microservices);
                    GatewayLaunchSettingsModifier.AddProfile(gatewayPath, env, gateway.GatewayProjectName);
                }
            }
        }