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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("SO115", new Info {
                    Title = "SO115", Version = "v1.0"
                });
            });

            ///<summary>
            ///Registrazione dei servizi AutoMapper
            /// </summary>
            services.AddAutoMapper(typeof(Startup));
            var config = new MapperConfigure().Configure();

            services.AddSingleton <IMapper>(sp => config.CreateMapper());

            ///<summary>
            ///Registrazione dei servizi Cors
            /// </summary>
            services.AddCors(options =>
            {
                options.AddPolicy("CorsSo115",
                                  builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(option =>
            {
                option.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
            services.AddSignalR();
            IntegrateSimpleInjector(services);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ///<summary>
            ///Registrazione dei servizi Cors
            /// </summary>
            ///
            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  builder =>
                {
                    builder
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials()
                    .WithOrigins(Configuration.GetSection("AllowedOriginLocal").Value,
                                 Configuration.GetSection("AllowedOriginTest").Value,
                                 Configuration.GetSection("AllowedOriginProd").Value,
                                 Configuration.GetSection("AllowedOriginMatrix").Value)
                    .SetIsOriginAllowedToAllowWildcardSubdomains()
                    .WithExposedHeaders("codicesede", "hubconnectionid", "idUtente", "localip", "DNT", "user-agent", "x-requested-with",
                                        "If-Modified-Since", "Cache-Control", "content-type", "range", "accept", "authorization", "origin");
                });
            });

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "test");
            services.AddSingleton(httpClient);
            services.AddControllers();

            services.AddControllersWithViews();
            services.AddHttpContextAccessor();

            services.AddMemoryCache();
            services.AddMvcCore().AddApiExplorer().AddNewtonsoftJson();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("SO115", new Microsoft.OpenApi.Models.OpenApiInfo {
                    Title = "SO115", Version = "v1.0"
                });
            });

            ///<summary>
            ///Registrazione dei servizi AutoMapper
            /// </summary>
            services.AddAutoMapper(typeof(Startup));
            var config = new MapperConfigure().Configure();

            services.AddSingleton <IMapper>(sp => config.CreateMapper());

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(option =>
            {
                option.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
            services.AddSignalR().AddHubOptions <NotificationHub>(options =>
            {
                options.EnableDetailedErrors = true;
            });
            IntegrateSimpleInjector(services);
        }