// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IAuthorService, AuthorService>(); ConfigureRepository.ConfDependenciesRepository(services); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddMvc(option => option.EnableEndpointRouting = false) .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); services.AddHttpClient <HttpClientAuthorsAPI>(client => { client.BaseAddress = new Uri("https://localhost:44392/api/authors/"); }); services.AddHttpClient <HttpClientBookAPI>(client => { client.BaseAddress = new Uri("https://localhost:44392/api/books/"); }); var config = new MapperConfiguration(cfg => { cfg.CreateMap <BookView, Book>(); }); IMapper mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddControllersWithViews(); services.AddRazorPages(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IAuthorService, AuthorService>(); services.AddTransient <IBookService, BookService>(); ConfigureRepository.ConfDependenciesRepository(services); services.AddControllers(); services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); var config = new MapperConfiguration(cfg => { cfg.CreateMap <AuthorView, Author>(); }); IMapper mapper = config.CreateMapper(); services.AddSingleton(mapper); var appsetings = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appsetings); var appseting = appsetings.Get <AppSettings>(); services.AddAuthentication(Options => { Options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; Options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; Options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.SaveToken = true; options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidAudience = "https://www.infnet.edu.br", ValidIssuer = "https://www.infnet.edu.br", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("assessmentWebAPIandMVC")) }; }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Estudo ASP.NET CORE com JWT", Contact = new OpenApiContact { Name = "Diego Bizarelo", Email = "*****@*****.**" } }); }); }