Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
            DefaultLogger.Info("Application initializing...");
            IWebHost webHost = CreateWebHostBuilder(args).Build();

            MainStaticDataProvider.Initialize(webHost.Services);
            DefaultLogger.Info("Application initialized!");
            webHost.Run();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();
            services.AddMvc(options =>
            {
                options.EnableEndpointRouting = false;
            }).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.TypeNameHandling      = Utilities.Serialization.JsonSerializer.Settings.TypeNameHandling;
                options.SerializerSettings.ReferenceLoopHandling = Utilities.Serialization.JsonSerializer.Settings.ReferenceLoopHandling;
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            services.AddResponseCompression(options =>
            {
                options.EnableForHttps = true;
            });

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo(enUSCulture),
                    new CultureInfo("tr-TR")
                };

                options.DefaultRequestCulture = new RequestCulture(culture: enUSCulture, uiCulture: enUSCulture);
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IPathProvider, PathProvider>();
            services.AddSingleton <IContextProvider, ContextProvider>();
            services.AddSingleton <IFlowConfigurationProvider, JsonFileBasedFlowConfigurationProvider>();
            services.AddSingleton <IFlowExecutionConfigurationProvider, JsonFileBasedFlowExecutionConfigurationProvider>();
            services.AddSingleton <IFlowProvider, FlowProvider>();
            services.AddSingleton <IIMDbDataProvider, DBBasedIMDbDataProvider>();
            services.AddSingleton <IExceptionHandler, ExceptionHandler>();
            services.AddSingleton <IElasticSearchConnectionProvider, ElasticSearchConnector>();
            services.AddSingleton <IAuthenticationProvider, DBAuthenticationProvider>();
            // Add our Config object so it can be injected
            services.Configure <AppConfiguration>(Configuration.GetSection(ConfigurationConstants.CustomConfigurationSectionName));
            services.Configure <CustomConfiguration>(Configuration.GetSection(ConfigurationConstants.CustomConfigurationSectionName));
            services.AddOptions();
            MainStaticDataProvider.RegisterProvider <IResourcesStaticDataProvider, ResourcesStaticDataProvider>(services);
            MainStaticDataProvider.RegisterProvider <IResultConfigurationsStaticDataProvider, ResultConfigurationsStaticDataProvider>(services);
            services.AddDbContext <JMoviesEntities>();
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();
            services.AddMvc(option =>
            {
                option.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
            }).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.TypeNameHandling      = Utilities.Serialization.JsonSerializer.Settings.TypeNameHandling;
                options.SerializerSettings.ReferenceLoopHandling = Utilities.Serialization.JsonSerializer.Settings.ReferenceLoopHandling;
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddAntiforgery(options =>
            {
                options.HeaderName = "X-XSRF-TOKEN";
            });
            services.AddDataProtection();
            // Add our Config object so it can be injected
            services.Configure <WebConfiguration>(Configuration.GetSection(ConfigurationConstants.CustomConfigurationSectionName));
            services.Configure <CustomConfiguration>(Configuration.GetSection(ConfigurationConstants.CustomConfigurationSectionName));
            services.AddOptions();
            services.AddSession(options =>
            {
                options.IdleTimeout     = TimeSpan.FromMinutes(5);
                options.Cookie.HttpOnly = true;
            }).AddAuthorization();
            services.AddResponseCompression(options =>
            {
                options.EnableForHttps = true;
            });

            byte[] signKey       = RandomHelper.GenerateRandom(256 / 8);
            byte[] encryptionKey = RandomHelper.GenerateRandom(256 / 8);
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
                options.SlidingExpiration = true;
                options.ExpireTimeSpan    = TimeSpan.FromMinutes(5);
                options.LoginPath         = "/login";
                options.AccessDeniedPath  = "/forbidden";
            })
            .AddJwtBearer(options =>
            {
                options.SaveToken = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey    = new SymmetricSecurityKey(signKey),
                    RequireSignedTokens = false,
                    TokenDecryptionKey  = new SymmetricSecurityKey(encryptionKey),
                    ValidAudience       = "jmovier",
                    ValidIssuer         = "jmovies",
                    ValidateLifetime    = true
                };
            });

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo(enUSCulture),
                    new CultureInfo(trTRCulture)
                };

                options.DefaultRequestCulture = new RequestCulture(culture: enUSCulture, uiCulture: enUSCulture);
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IContextProvider, SessionBasedContextProvider>();
            services.AddSingleton <IPathProvider, PathProvider>();
            services.AddSingleton <IJMAppClientProvider, JMAppClientProvider>();
            services.AddSingleton <IFlowConfigurationProvider, JsonFileBasedFlowConfigurationProvider>();
            services.AddSingleton <IFlowExecutionConfigurationProvider, JsonFileBasedFlowExecutionConfigurationProvider>();
            services.AddSingleton <IIMDbDataProvider, ActionBasedIMDbDataProvider>();
            services.AddSingleton <IExceptionHandler, ExceptionHandler>();
            services.AddSingleton <IAuthenticationProvider, FlowBasedAuthenticationProvider>();
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <ITokenProvider, JWTTokenProvider>((serviceProvider) =>
            {
                return(new JWTTokenProvider(signKey, encryptionKey));
            });
            MainStaticDataProvider.RegisterProvider <IResourcesStaticDataProvider, ResourcesStaticDataProvider>(services);
            MainStaticDataProvider.RegisterProvider <IResultConfigurationsStaticDataProvider, ResultConfigurationsStaticDataProvider>(services);
        }