Esempio n. 1
0
        private static void InstallHavitEntityFramework(IServiceCollection services, InstallConfiguration configuration)
        {
            DbContextOptions options = configuration.UseInMemoryDb
                                ? new DbContextOptionsBuilder <NewProjectTemplateDbContext>().UseInMemoryDatabase(nameof(NewProjectTemplateDbContext)).Options
                                : new DbContextOptionsBuilder <NewProjectTemplateDbContext>().UseSqlServer(configuration.DatabaseConnectionString, c => c.MaxBatchSize(30)).Options;

            services.WithEntityPatternsInstaller()
            .AddEntityPatterns()
            //.AddLocalizationServices<Language>()
            .AddDbContext <NewProjectTemplateDbContext>(options)
            .AddDataLayer(typeof(IApplicationSettingsDataSource).Assembly)
            .AddLookupService <ICountryByIsoCodeLookupService, CountryByIsoCodeLookupService>();

            services.AddSingleton <IEntityValidator <object>, ValidatableObjectEntityValidator>();
        }
Esempio n. 2
0
        public static IServiceCollection ConfigureForWebServer(this IServiceCollection services, IConfiguration configuration)
        {
            FileStorageOptions fileStorageOptions = new FileStorageOptions();

            configuration.GetSection(FileStorageOptions.FileStorageOptionsKey).Bind(fileStorageOptions);

            InstallConfiguration installConfiguration = new InstallConfiguration
            {
                DatabaseConnectionString       = configuration.GetConnectionString("Database"),
                AzureStorageConnectionString   = configuration.GetConnectionString("AzureStorageConnectionString"),
                FileStoragePathOrContainerName = fileStorageOptions.PathOrContainerName,
                ServiceProfiles = new[] { ServiceAttribute.DefaultProfile, ServiceProfiles.WebServer },
            };

            return(services.ConfigureForAll(installConfiguration));
        }
Esempio n. 3
0
        public static IServiceCollection ConfigureForTests(this IServiceCollection services, bool useInMemoryDb = true)
        {
            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Developement";

            IConfigurationRoot configuration = new ConfigurationBuilder()
                                               .SetBasePath(Directory.GetCurrentDirectory())
                                               .AddJsonFile("appsettings.json")
                                               .AddJsonFile($"appsettings.{environment}.json", true)
                                               .Build();

            InstallConfiguration installConfiguration = new InstallConfiguration
            {
                DatabaseConnectionString = configuration.GetConnectionString("Database"),
                ServiceProfiles          = new[] { ServiceAttribute.DefaultProfile },
                UseInMemoryDb            = useInMemoryDb,
            };

            return(services.ConfigureForAll(installConfiguration));
        }
Esempio n. 4
0
        private static void InstallFileServices(IServiceCollection services, InstallConfiguration configuration)
        {
            services.AddFileStorageWrappingService <IApplicationFileStorageService, ApplicationFileStorageService, ApplicationFileStorage>();

            if (!String.IsNullOrWhiteSpace(configuration.AzureStorageConnectionString))
            {
                throw new NotImplementedException("TODO - register AzureBlobStorageService");
                //services.AddAzureBlobStorageService<ApplicationFileStorage>(new AzureBlobStorageServiceOptions<ApplicationFileStorage>
                //{
                //	BlobStorage = configuration.AzureStorageConnectionString,
                //	ContainerName = configuration.FileStoragePathOrContainerName,
                //	TokenCredential = new DefaultAzureCredential()
                //});
            }
            else
            {
                services.AddFileSystemStorageService <ApplicationFileStorage>(configuration.FileStoragePathOrContainerName?.Replace("%TEMP%", Path.GetTempPath()));
            }
        }
Esempio n. 5
0
        private static IServiceCollection ConfigureForAll(this IServiceCollection services, InstallConfiguration installConfiguration)
        {
            InstallHavitEntityFramework(services, installConfiguration);
            InstallHavitServices(services);
            InstallByServiceAttribute(services, installConfiguration);
            InstallAuthorizationHandlers(services);
            InstallFileServices(services, installConfiguration);

            services.AddMemoryCache();

            return(services);
        }
Esempio n. 6
0
 private static void InstallByServiceAttribute(IServiceCollection services, InstallConfiguration configuration)
 {
     services.AddByServiceAttribute(typeof(Havit.NewProjectTemplate.DataLayer.Properties.AssemblyInfo).Assembly, configuration.ServiceProfiles);
     services.AddByServiceAttribute(typeof(Havit.NewProjectTemplate.Services.Properties.AssemblyInfo).Assembly, configuration.ServiceProfiles);
     services.AddByServiceAttribute(typeof(Havit.NewProjectTemplate.Facades.Properties.AssemblyInfo).Assembly, configuration.ServiceProfiles);
 }