예제 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var section = Configuration.GetSection("Blogifier");

            services.AddAppSettings <AppItem>(section);

            AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString"));

            services.AddDbContext <AppDbContext>(AppSettings.DbOptions);

            services.AddIdentity <AppUser, IdentityRole>()
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc()
            .ConfigureApplicationPartManager(p =>
            {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            })
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Admin");
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAppServices();
        }
예제 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var section = Configuration.GetSection("Blogifier");

            services.AddAppSettings <AppItem>(section);

            if (section.GetValue <string>("DbProvider") == "SqlServer")
            {
                AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue <string>("ConnString"));
            }
            else if (section.GetValue <string>("DbProvider") == "MySql")
            {
                AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString"));
            }
            else
            {
                AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString"));
            }

            services.AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient);

            services.AddIdentity <AppUser, IdentityRole>(options => {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 4;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.User.AllowedUserNameCharacters  = null;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            services.AddMvc()
            .ConfigureApplicationPartManager(p =>
            {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            })
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Admin");
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAppServices();
        }
예제 #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbProvider(Configuration);

            services.AddSecurity();

            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            services.AddAppLocalization();

            services.AddRouting(options => options.LowercaseUrls = true);

            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options
                            .AllowAnyOrigin()
                            .AllowAnyHeader()
                            .AllowAnyMethod()
                            );
            });

            services.AddControllersWithViews()
            .AddViewLocalization()
            .ConfigureApplicationPartManager(p =>
            {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            });

            if (Environment.IsDevelopment())
            {
                services.AddSwagger();
            }

            services.AddRazorPages(
                options => options.Conventions.AuthorizeFolder("/Admin")
                );

            //services.AddServerSideBlazor();

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "wwwroot/themes/_active";
            });

            services.AddAppServices();
        }
예제 #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            var section = Configuration.GetSection("Blogifier");

            services.AddAppSettings <AppItem>(section);

            if (section.GetValue <string>("DbProvider") == "SqlServer")
            {
                AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue <string>("ConnString"));
            }
            else if (section.GetValue <string>("DbProvider") == "MySql")
            {
                AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString"));
            }
            else if (section.GetValue <string>("DbProvider") == "Postgres")
            {
                AppSettings.DbOptions = options => options.UseNpgsql(section.GetValue <string>("ConnString"));
            }
            else
            {
                AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString"));
            }

            services.AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient);

            services.AddIdentity <AppUser, IdentityRole>(options => {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 4;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.User.AllowedUserNameCharacters  = null;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            services.AddJsonLocalization();

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("es-ES"),
                    new CultureInfo("pt-BR"),
                    new CultureInfo("ru-RU"),
                    new CultureInfo("zh-cn"),
                    new CultureInfo("zh-tw")
                };

                options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            services.AddRouting(options => options.LowercaseUrls = true);

            services.AddMvc()
            .AddViewLocalization()
            .ConfigureApplicationPartManager(p =>
            {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            })
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Admin");
            })
            .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly).AddControllersAsServices()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSwaggerGen(setupAction => {
                setupAction.SwaggerDoc("spec",
                                       new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title   = "Blogifier API",
                    Version = "1"
                });
                setupAction.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "CoreAPI.xml"));
            });

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "wwwroot/themes/_active";
            });
            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options
                            .AllowAnyOrigin()
                            .AllowAnyHeader()
                            .AllowAnyMethod()
                            );
            });

            services.AddAppServices();
        }
예제 #5
0
        public void ConfigureServices(IServiceCollection services)
        {
            var section = Configuration.GetSection("Blogifier");

            services.AddAppSettings <AppItem>(section);

            if (section.GetValue <string>("DbProvider") == "SqlServer")
            {
                AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue <string>("ConnString"));
            }
            else if (section.GetValue <string>("DbProvider") == "MySql")
            {
                AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString"));
            }
            else
            {
                AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString"));
            }

            services.AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient);

            services.AddIdentity <AppUser, IdentityRole>(options => {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 4;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.User.AllowedUserNameCharacters  = null;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            services.AddJsonLocalization();

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("ru-RU"),
                    new CultureInfo("zh-cn"),
                    new CultureInfo("zh-tw")
                };

                options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            services.AddRouting(options => options.LowercaseUrls = true);

            services.AddMvc()
            .AddViewLocalization()
            .ConfigureApplicationPartManager(p =>
            {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            })
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Admin");
            })
            .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly).AddControllersAsServices()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAppServices();
        }
예제 #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            var section = Configuration.GetSection("Blogifier");

            services.AddAppSettings <AppItem>(section);

            if (section.GetValue <string>("DbProvider") == "SqlServer")
            {
                //AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue<string>("ConnString"));
                throw new NotSupportedException();
            }
            else if (section.GetValue <string>("DbProvider") == "MySql")
            {
                AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString"));
            }
            else
            {
                AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString"));
            }


            services
            .AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient);

            services.AddIdentity <AppUser, IdentityRole>(options => {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 4;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.User.AllowedUserNameCharacters  = null;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            services.AddJsonLocalization(options => {
                //"Resources" by default
                //options.ResourcesPath;
            });

            services.ConfigureLocalizationOptions();

            services.AddRouting(options => {
                options.LowercaseUrls       = true;
                options.AppendTrailingSlash = true;
            });

            services.AddRazorPages();
            services.AddMvc()
            .AddViewLocalization()
            .ConfigureApplicationPartManager(p => {
                foreach (var assembly in AppConfig.GetAssemblies())
                {
                    p.ApplicationParts.Add(new AssemblyPart(assembly));
                }
            })
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Admin");
            })
            .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly)
            .AddControllersAsServices()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddSwaggerGen(setupAction => {
                setupAction.SwaggerDoc("spec",
                                       new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title   = "Blogifier API",
                    Version = "1"
                });
                setupAction.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "CoreAPI.xml"));
            });

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "Custom/themes/custom";
            });
            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
            });

            services.AddAppServices();
        }