Exemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            //services.AddAuthentication("Bearer")
            //    .AddJwtBearer("Bearer", options =>
            //    {
            //        options.Authority = "https://localhost:5001";

            //        options.TokenValidationParameters = new TokenValidationParameters
            //        {
            //            ValidateAudience = false
            //        };
            //    });
            //services.AddAuthorization(options =>
            //{
            //    options.AddPolicy("ApiScope", policy =>
            //    {
            //        policy.RequireAuthenticatedUser();
            //        policy.RequireClaim("scope", "fmApiScope");
            //    });
            //});
            var connectionString = Configuration.GetConnectionString("FinangerConnection");

            if (!string.IsNullOrEmpty(connectionString))
            {
                services.AddDbContext <FinangerContext>(options => options.UseSqlServer(connectionString));
            }

            services.AddScoped <IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));
            services.AddScoped <FinangerSchema>();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "FinangerSwagger", Version = "v1"
                });
            });
            var config = new AutoMapper.MapperConfiguration(cfg =>
            {
                DependencyInjector.UpdateAutoMapperConfiguration(cfg);
            });
            var mapper = config.CreateMapper();

            services.AddSingleton(mapper);
            DependencyInjector.ConfigureAll(services);
        }