Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var env = services.FirstOrDefault(x => x.ServiceType == typeof(IWebHostEnvironment)).ImplementationInstance as IWebHostEnvironment;

            ConfigureDependencyInjection(services, env);

            services.AddDbContextPool <BloggingContext>(options =>
            {
                ContextFactory.ConfigureDBKind(options, Configuration);
            });
            services.AddDbContextPool <InkBall.Module.Model.GamesContext>(options =>
            {
                ContextFactory.ConfigureDBKind(options, Configuration);
            });

            ConfigureAuthenticationAuthorizationHelper(services, env);

            ConfigureDistributedCache(Configuration, services);

            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                options.IdleTimeout         = TimeSpan.FromMinutes(60);
                options.Cookie.Path         = Configuration["AppRootPath"].TrimEnd('/');
                options.Cookie.HttpOnly     = true;
                options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
                options.Cookie.SameSite     = SameSiteMode.Strict;
            });

            // Add framework services.
            services.AddControllersWithViews(options =>
            {
                options.UseCentralRoutePrefix <PageController>(new RouteAttribute("idm"));
            }).AddSessionStateTempDataProvider();
            services.AddRazorPages();

            var protection_builder = services.AddDataProtection()
                                     //.SetDefaultKeyLifetime(TimeSpan.FromDays(14))	//the default id 90 days - enough
                                     .PersistKeysToDbContext <BloggingContext>();

            if (!string.IsNullOrEmpty(Configuration["DataProtection:CertFile"]))
            {
                protection_builder.ProtectKeysWithCertificate(new X509Certificate2(Configuration["DataProtection:CertFile"], Configuration["DataProtection:CertPassword"]));
            }


            services.AddSignalR(options =>
            {
                options.EnableDetailedErrors = true;
                //options.SupportedProtocols = new System.Collections.Generic.List<string>(new[] { "websocket" });
#if DEBUG
                options.KeepAliveInterval     = TimeSpan.FromSeconds(30);
                options.ClientTimeoutInterval = options.KeepAliveInterval * 2;
#endif
            })
            .AddJsonProtocol(options =>
            {
                //options.PayloadSerializerSettings.ContractResolver = new DefaultContractResolver();
            })
            .AddMessagePackProtocol(options =>
            {
                //options.SerializerOptions.WithResolver(MessagePack.Resolvers.StandardResolver.Instance);
                options.SerializerOptions = MessagePackSerializerOptions
                                            .Standard
                                            .WithResolver(MessagePack.Resolvers.StandardResolver.Instance)
                                            .WithSecurity(MessagePackSecurity.UntrustedData);
            });
        }
Exemple #2
0
 void ConfigureDistributedCache(IConfiguration configuration, IServiceCollection services)
 {
     ContextFactory.ConfigureDBKind(null, configuration, services);
 }