// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => options.Filters.Add(new ApiExceptionFilter())).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "API Net Core", Description = "My ASP.NET Core Web API", TermsOfService = "None", Contact = new Contact() { Name = "Enrique Inca Q.", Email = "*****@*****.**", Url = "" } }); }); services.AddCors(); MongoDbPersistence.Configure(); AutoMapperConfiguracion.Configure(); RegisterServices(services); // configure strongly typed settings objects var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <Settings>(appSettingsSection); // configure jwt authentication var settings = appSettingsSection.Get <Settings>(); var key = Encoding.ASCII.GetBytes(settings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; }); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <SalesDbContext>( options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) ); services.AddMvc(); //Register Generic Repository services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>)); services.AddTransient <IUnitOfWork, UnitOfWork <SalesDbContext> >(); // Automapper Configuration AutoMapperConfiguracion.Configure(); //Register services services.AddScoped <ICategoryService, CategoryService>(); }