// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var connection = Configuration["MySQLConnection:MySQLConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connection)); if (Environment.IsDevelopment()) { MigrateDatabase(connection); } var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); filterOptions.ContentResponseEnricherList.Add(new BookEnricher()); services.AddSingleton(filterOptions); //Api versioning services.AddApiVersioning(); //Dependency Injection services.AddScoped <IPersonBusiness, PersonBusinessImplementation>(); services.AddScoped <IBookBusiness, BookBusinessImplementation>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
private void RegisterHATEOAS(IServiceCollection services) { var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); services.AddSingleton(filterOptions); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration["MySQLConnection:MySQLConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connection, ServerVersion.AutoDetect(connection))); if (Environment.IsDevelopment()) { MigrateDatebase(connection); } services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml")); options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json")); }).AddXmlSerializerFormatters(); var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseList.Add(new PersonResponse()); services.AddSingleton(filterOptions); services.AddApiVersioning(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API's toStudy", Version = "v1", Description = "API's to Study", Contact = new OpenApiContact { Name = "Denis Missias", Url = new Uri("https://github.com/denismissias") } }); }); services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllers(); services.AddScoped(typeof(IRepository <>), typeof(Repository <>)); services.AddScoped(typeof(IMapper <PersonResource, Person>), typeof(PersonMapper <PersonResource, Person>)); services.AddScoped(typeof(IMapper <Person, PersonResource>), typeof(PersonMapper <Person, PersonResource>)); services.AddScoped(typeof(IMapper <BookResource, Book>), typeof(BookMapper <BookResource, Book>)); services.AddScoped(typeof(IMapper <Book, BookResource>), typeof(BookMapper <Book, BookResource>)); services.AddScoped <IPersonService, PersonService>(); services.AddScoped <IBookService, BookService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllers(); var connection = Configuration["MySQLConnection:MySQLConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connection)); if (Environment.IsDevelopment()) { MigrateDatabase(connection); } var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); filterOptions.ContentResponseEnricherList.Add(new BookEnricher()); services.AddSingleton(filterOptions); //Api versioning services.AddApiVersioning(); //Swagger implementation services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "REST API's From Zero To Azure With ASP.NET Core 5 and Docker", Version = "v1", Description = "API RESTful developed in course 'REST API's From Zero To Azure With ASP.NET Core 5 and Docker'", Contact = new OpenApiContact { Name = "Luiz Felipe Rosa da Silveira", Url = new Uri("https://github.com/luizfelipers19") } }); }); //Dependency Injection services.AddScoped <IPersonBusiness, PersonBusinessImplementation>(); services.AddScoped <IBookBusiness, BookBusinessImplementation>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var tokenConfigurations = new TokenConfiguration(); new ConfigureFromConfigurationOptions <TokenConfiguration>( Configuration.GetSection("TokenConfigurations") ) .Configure(tokenConfigurations); services.AddSingleton(tokenConfigurations); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenConfigurations.Issuer, ValidAudience = tokenConfigurations.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenConfigurations.Secret)) }; }); services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build() ); }); services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllers(); var connection = Configuration["MySQLConnection:MySQLConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connection)); if (Environment.IsDevelopment()) { MigrateDatabase(connection); } var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); filterOptions.ContentResponseEnricherList.Add(new BookEnricher()); services.AddSingleton(filterOptions); //Api versioning services.AddApiVersioning(); //Swagger implementation services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "REST API's From Zero To Azure With ASP.NET Core 5 and Docker", Version = "v1", Description = "API RESTful developed in course 'REST API's From Zero To Azure With ASP.NET Core 5 and Docker'", Contact = new OpenApiContact { Name = "Luiz Felipe Rosa da Silveira", Url = new Uri("https://github.com/luizfelipers19") } }); }); //Dependency Injection services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IPersonBusiness, PersonBusinessImplementation>(); services.AddScoped <IBookBusiness, BookBusinessImplementation>(); services.AddScoped <ILoginBusiness, LoginBusinessImplementation>(); services.AddScoped <IFileBusiness, FileBusinessImplementation>(); services.AddTransient <ITokenService, TokenService>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IPersonRepository, PersonRepository>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Adicionar as configurações do token setadas no appsettings.json var tokenConfigurations = new TokenConfiguration(); new ConfigureFromConfigurationOptions <TokenConfiguration>( Configuration.GetSection("TokenConfiguration") ).Configure(tokenConfigurations); services.AddSingleton(tokenConfigurations); //definir parametros de autenticação services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenConfigurations.Issuer, ValidAudience = tokenConfigurations.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenConfigurations.Secret)) }; }); //autorizar autenticação services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build()); }); //Adicionar CORS services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllers(); //Adicionando DbContext var connection = Configuration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySqlContext>(options => options.UseMySql(connection)); if (Environment.IsDevelopment()) { MigrateDatabase(connection); } //Aceitar serviços XML services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml")); options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json")); }).AddXmlSerializerFormatters(); var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); services.AddSingleton(filterOptions); //Adicionando servico para gerenciamento de versoes da minha API services.AddApiVersioning(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API CRUD WITH ASP .NET CORE 5 AND MYSQL", Version = "v1", Description = "API RESTful developed in course", Contact = new OpenApiContact { Name = "Milena Ramiro", Url = new Uri("https://github.com/milena-ramiro") } }); }); //Injections services.AddScoped <IPessoaBusiness, PessoaBusinessImplementation>(); services.AddScoped <ILivroBusiness, LivroBusinessImplementation>(); services.AddScoped <ILoginBusiness, LoginBusinessImplementation>(); services.AddTransient <ITokenService, TokenService>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IPessoaRepository, PessoaRepository>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var tokenConfigurations = new TokenConfiguration(); new ConfigureFromConfigurationOptions <TokenConfiguration>( Configuration.GetSection("TokenConfiguration") ).Configure(tokenConfigurations); services.AddSingleton(tokenConfigurations); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenConfigurations.Issuer, ValidAudience = tokenConfigurations.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenConfigurations.Secret)) }; }); services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder().AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build()); }); services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllers(); var connection = Configuration["MySQLConnection:MySQLConnectionString"]; services.AddApiVersioning(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo() { Title = "RestAPI", Version = "v1", Description = "API RESTfull developed", Contact = new OpenApiContact() { Name = "Rafael Garcia", Url = new Uri("https://github.com/") } }); }); services.AddDbContext <ContextMySql>(options => options.UseMySql(connection)); if (Environment.IsDevelopment()) { MigrateDatabase(connection); } services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; //Isso é para aceitar a propriedade que vier setado no accept do header options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml").ToString()); options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json").ToString()); }).AddXmlSerializerFormatters(); var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new PersonEnricher()); services.AddSingleton(filterOptions); services.AddTransient <ITokenService, TokenService>(); services.AddScoped <ILoginService, LoginService>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <CalculatorService>(); services.AddScoped <IPersonService, PersonService>(); services.AddScoped <IBookService, BooksService>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //setar valores do appSettings var tokenConfigurations = new TokenConfiguration(); // armazena os valores na classe new ConfigureFromConfigurationOptions <TokenConfiguration>( Configuration.GetSection("TokenConfigurations") ) .Configure(tokenConfigurations); //injetando no serviço uma instancia services.AddSingleton(tokenConfigurations); // parametros de autenticação services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenConfigurations.Issuer, ValidAudience = tokenConfigurations.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenConfigurations.Secret)) }; }); // add autorização services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build()); }); services.AddCors(options => options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddControllersWithViews(); services.AddDbContext <ContextSql> (options => options.UseSqlServer (Configuration.GetConnectionString("DefaultConnection"))); services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; options.FormatterMappings.SetMediaTypeMappingForFormat("xml", MediaTypeHeaderValue.Parse("application/xml")); options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json")); }) .AddXmlSerializerFormatters(); var filterOptions = new HypermediaFilterOptions(); filterOptions.ContentResponseEnricherList.Add(new ScheduleFormEnricher()); services.AddSingleton(filterOptions); //Adicionando versionamento API // services.AddApiVersioning(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Schedule Beauty Website/API", Version = "v1", Description = "Fundatec:Trabalho de Conclusão > \"Orientador: Prof.Guilherme Elias\" .", Contact = new OpenApiContact { Name = "Schedule Beauty", Url = new Uri("https://localhost:44370/ScheduleForms/Agenda"), } }); }); services.AddScoped <IScheduleFormsBusiness, ScheduleFormsBusinessImplementation>(); services.AddScoped <ILoginBusiness, LoginBusinessImplementation>(); services.AddTransient <ITokenService, TokenService>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IScheduleFormRepository, ScheduleFormRepository>(); services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepositoryImplementation <>)); }