Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddNewtonsoftJson()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
                options.JsonSerializerOptions.WriteIndented        = true;
            });

            services.AddDbContext <ApplicationDBContext>(opt =>
                                                         opt.UseNpgsql(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                         );
            ApplicationDBContext.ConfigureServices(services);

            services.AddDbContext <ShopDBContext>(opt =>
                                                  opt.UseNpgsql(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                  );
            ShopDBContext.ConfigureServices(services);

            services.AddMemoryCache();
            services.AddScoped <ICacheBase, CacheBase>();
            services.AddScoped <UserInfoCache>();
            services.AddScoped <ConfigurationCache>();
            services.AddHostedService <QueuedHostedService>();
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            services.AddScoped <AppSettings>();
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath = "/Login/Index/";
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            services.AddDbContext <ApplicationDBContext>(opt =>
                                                         opt.UseNpgsql(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                         );
            ApplicationDBContext.ConfigureServices(services);

            services.AddDbContext <ShopDBContext>(opt =>
                                                  opt.UseNpgsql(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                  );
            ShopDBContext.ConfigureServices(services);
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddRazorPages();

            services.AddDbContext <ApplicationDBContext>(opt =>
                                                         opt.UseSqlServer(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                         );
            ApplicationDBContext.ConfigureServices(services);

            services.AddDbContext <ShopDBContext>(opt =>
                                                  opt.UseSqlServer(Configuration.GetConnectionString("NpgsqlConection"), b => b.MigrationsAssembly("DatabaseTools"))
                                                  );
            ShopDBContext.ConfigureServices(services);
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddNewtonsoftJson()
            .AddJsonOptions(jsonOptions =>
            {
                jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
                jsonOptions.JsonSerializerOptions.WriteIndented        = true;
                jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
            });
            services.AddHttpContextAccessor();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
            services.AddRazorPages();
            services.AddDbContext <ApplicationDBContext>(opt =>
            {
                opt.UseSqlServer(Configuration.GetConnectionString("NpgsqlConection"),
                                 b => b.MigrationsAssembly("DatabaseTools"));
            }, ServiceLifetime.Transient);
            ApplicationDBContext.ConfigureServices(services);

            services.AddDbContext <ShopDBContext>(opt =>
            {
                opt.UseSqlServer(Configuration.GetConnectionString("NpgsqlConection"),
                                 b => b.MigrationsAssembly("DatabaseTools"));
            }, ServiceLifetime.Transient);
            ShopDBContext.ConfigureServices(services);
            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
            services.AddMemoryCache();
            services.AddScoped <ICacheBase, CacheBase>();
            services.AddScoped <UserInfoCache>();
            services.AddScoped <ConfigurationCache>();
            services.AddHostedService <QueuedHostedService>();
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            services.AddScoped <AppSettings>();
            services.AddScoped <EnCryptography>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddDistributedMemoryCache();
            services.AddSession(options => {
                options.IdleTimeout     = TimeSpan.FromMinutes(30);
                options.Cookie.HttpOnly = true;
            });
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.LoginPath         = "/Login/Index/";
                options.LogoutPath        = new PathString("/Login/logout");
                options.AccessDeniedPath  = "/Login/Index/";
                options.ExpireTimeSpan    = TimeSpan.FromDays(1);
                options.SlidingExpiration = false;
            });
            services.AddLogging(logging =>
            {
                logging.AddConsole();
                logging.AddDebug();
            });
            services.AddSignalR(o =>
            {
                o.EnableDetailedErrors = true;
            });
            services.AddCors();
            services.Configure <PaypalApiSetting>(Configuration.GetSection("Paypal"));
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddAutoMapper(typeof(Startup));
            services.Configure <IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });
        }