// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <DataContext>(options => options.UseNpgsql(_utilities.GetConnectionString(Configuration))); // ASP.NET Core Identity services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <DataContext>() .AddDefaultTokenProviders(); // JSON Web Token var jwtConfiguration = new JwtConfiguration(services); jwtConfiguration.Configure(Configuration.GetSection("AppSettings")); services.AddScoped <LineService>(); services.AddScoped <CompaniesService>(); // AutoMapper var mapper = new MapperConfiguration(config => config.AddProfile <LineModelToDTO>() ); services.AddCors(_utilities.SetCorsPolicy); services.AddSingleton(mapper.CreateMapper()); }
public void ConfigureServices(IServiceCollection services) { BusinessConfiguration.ConfigureServices(services, Configuration); BusinessConfiguration.ConfigureIdentityInicializerAsync(services.BuildServiceProvider()); JwtConfiguration.Configure(services, Configuration); services.AddControllers(mvcOtions => { mvcOtions.EnableEndpointRouting = false; }); services.AddScoped(typeof(UserService)); services.AddScoped <ExceptionFilter>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "TimeOffTrackerApi", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.Http, Scheme = "Bearer", BearerFormat = "JWT", In = ParameterLocation.Header, Description = "JWT Authorization header using the Bearer scheme." }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] {} } }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); //Setup para configuração do CORS CorsConfiguration.UseCors(app); JwtConfiguration.Configure(app); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //Setup para configuração do Swagger SwaggerConfiguration.UseSwagger(app); }
public static void IdentityModuleRegister(this IServiceCollection services, IConfiguration configuration) { IdentityConfiguration.Configure(services, configuration); JwtConfiguration.Configure(services, configuration); }