예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(opt =>
            {
                opt.AddPolicy("CorsPolicy", policy =>
                {
                    policy
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .WithOrigins("http://localhost:4200")
                    .AllowCredentials();
                });
            });

            var tokenOptions = Configuration.GetSection("JwtTokenOptions").Get <JwtTokenOptions>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt =>
            {
                opt.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidIssuer              = tokenOptions.Issuer,
                    ValidAudience            = tokenOptions.Audience,
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = SecurityKeyHelper.CreateSecurity(tokenOptions.SecurityKey)
                };
            });

            services.AddDbContext <PapyrusContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString("PostgresSqlConnection"));
            });

            // services.AddDbContext<PapyrusContext>(options =>
            // {
            //     options.UseSqlServer(Configuration.GetConnectionString("MssqlConnection"));
            // });

            services.AddControllers()
            .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            services.Configure <CloudinarySettings>(Configuration.GetSection("CloudinarySettings"));

            services.AddDependencyResolvers(new ICoreModule[]
            {
                new CoreModule(),
            });
        }