Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // configure strongly typed settings objects from appsettings.json file
            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);


            // configure DB
            services.AddDbContext <NebulaChatDbContext>(options =>
                                                        options.UseSqlServer(
                                                            Configuration.GetConnectionString("DefaultConnection")));

            // configure cors
            services.AddCors(options => options.AddPolicy("NebulaChatCorsPolicy",
                                                          builder =>
            {
                builder.AllowAnyMethod().AllowAnyHeader()
                .WithOrigins(appSettingsSection.Get <AppSettings>().ClientUrl)
                .AllowCredentials();
            }));

            // configure jwt authentication
            JwtAuthConfiguration.Configure(services, appSettingsSection);

            services.AddAutoMapper();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSignalR(options => options.EnableDetailedErrors = true);

            // Set dependency injection
            DependencyInjectionConfiguration.Configure(services);
        }
 public JwtSecurityTokenService(JwtAuthConfiguration jwtAuthConfiguration)
 {
     this.jwtAuthConfiguration    = jwtAuthConfiguration;
     this.jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
 }