コード例 #1
0
ファイル: Startup.cs プロジェクト: amila-k/Movie-rating-svc
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Bookshop API", Version = "v1"
                });
            });

            services.AddCors(options =>
            {
                options.AddPolicy(name: "allOrigins",
                                  Builders =>
                {
                    Builders.AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowAnyOrigin();
                });
            });

            var identityUrl = Configuration.GetValue <string>("Authentication:Authority");

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.Authority            = identityUrl;
                options.RequireHttpsMetadata = false;
                options.Audience             = "socialnetworkresource";
            });

            ConfigureAutoMapper(services);

            services.RegisterCustomServices(HostingEnvironment.WebRootPath);

            services.AddDbContext <ShowContext>(options =>
                                                options.UseSqlServer(Configuration.GetConnectionString("Default")));
        }