public void ConfigureServices(IServiceCollection services) { var cns = Configuration .GetSection("ConfigConnectionString:Default").Value; services.AddIdentityServer() .AddSigningCredential(GetRSAParameters()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients(Configuration.GetSection("ConfigSettings").Get <ConfigSettingsBase>())); //for clarity of the next piece of code services.AddScoped <CurrentUser>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); services.AddAuthentication() .AddGoogle(options => { options.ClientId = "857854978384-sv33ngtei50k8fn5ea37rcddo08n0ior.apps.googleusercontent.com"; options.ClientSecret = "x1SWT89gyn5LLLyMNFxEx_Ss"; }); // Add cross-origin resource sharing services Configurations Cors.Enable(services); services.AddMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //per https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#routing-startup-code // static files should be called before UseRouting StaticFiles.Configure(app, env); app.UseRouting(); Cors.Configure(app, env); Authentication.Configure(app, env); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHub <ChatHub>("/chathub"); endpoints.MapHub <NotificationHub>("/notificationhub"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHttpsRedirection(); app.UseDeveloperExceptionPage(); app.UseHsts(); } MVC.Configure(app, env); SPA.Configure(app, env); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { Authentication.Configure(app, env); Cors.Configure(app, env); //app.UseSignalR(routes => //{ // routes.MapHub<ChatHub>("/chathub"); //}); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHttpsRedirection(); app.UseDeveloperExceptionPage(); app.UseHsts(); } MVC.Configure(app, env); SPA.Configure(app, env); StaticFiles.Configure(app, env); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DbContextCalemas.Erp>( options => options.UseSqlServer( Configuration .GetSection("EFCoreConnStrings:Calemas.Erp").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Calemas.Erp").Value; options.InstanceName = "Calemas.Erp"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); // Add cross-origin resource sharing services Configurations Cors.Enable(services); // Add application services. ConfigContainerCalemas.Erp.Config(services); // Add framework services. services.AddMvc(); }
public void ConfigureServices(IServiceCollection services) { Cors.AddCors(services); Identity.AddIdentity(services); Authentication.AddAuthentication(Configuration, services); Interfaces.AddInterfaces(services); ModelValidations.AddModelValidation(services); services.Configure <RazorViewEngineOptions>(options => options.ViewLocationExpanders.Add(new ViewLocationExpander())); services.AddAntiforgery(options => { options.Cookie.Name = "_af"; options.Cookie.HttpOnly = true; options.Cookie.SecurePolicy = CookieSecurePolicy.Always; options.HeaderName = "X-XSRF-TOKEN"; }); services.AddAutoMapper(typeof(Startup)); services.AddDbContext <AppDbContext>(); services.AddScoped <ModelValidationAttribute>(); services.AddControllersWithViews() .AddNewtonsoftJson(options => { options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; }) .AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining <Startup>()); services.AddEmailSenders(); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = _ => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.Configure <EmailSettings>(options => Configuration.GetSection("EmailSettings").Bind(options)); services.Configure <TokenSettings>(options => Configuration.GetSection("TokenSettings").Bind(options)); services.Configure <TestingEnvironment>(options => Configuration.GetSection("TestingEnvironment").Bind(options)); services.Configure <DirectoryLocations>(options => Configuration.GetSection("DirectoryLocations").Bind(options)); }
// 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.UseHttpsRedirection(); app.UseRouting(); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("swagger/v1/swagger.json", "Shop API V1 Documentation"); }); app.UseCors(Cors => Cors .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void ConfigureServices(IServiceCollection services) { var cns = Configuration .GetSection("EFCoreConnStrings:Target").Value; services.AddDbContext <DbContextTarget>(options => options.UseSqlServer(cns)); //var migrationAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; //services.AddDbContext<DbContextTarget>(options => options.UseSqlServer(cns)); services.AddIdentityServer() .AddSigningCredential(GetRSAParameters()) //.AddTemporarySigningCredential() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients(Configuration.GetSection("ConfigSettings").Get <ConfigSettingsBase>())); //.AddConfigurationStore(builder => // builder.UseSqlServer(cns, options => // options.MigrationsAssembly(migrationAssembly))) // .AddOperationalStore(builder => // builder.UseSqlServer(cns, options => // options.MigrationsAssembly(migrationAssembly))); //for clarity of the next piece of code services.AddScoped <CurrentUser>(); services.AddTransient <IUsuarioRepository, UsuarioRepository>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); //Add cross-origin resource sharing services Configurations Cors.Enable(services); services.AddMvc(); }
private static void ConfigureCors(IApplicationBuilder app, Cors cors) { if (cors.Enabled) { app.UseCors(builder => builder .WithOrigins("http://localhost:3000", "http://localhost:5000") .WithHeaders("authorization", "content-type", "cache-control", "pragma", "expires", "if-modified-since") .WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")); } }
public void ConfigureServices(IServiceCollection services) { var cns = Configuration .GetSection("ConfigConnectionString:Default").Value; var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.AddIdentityServer() .AddSigningCredential(GetRSAParameters()) //.AddInMemoryApiResources(Config.GetApiResources()) //.AddInMemoryIdentityResources(Config.GetIdentityResources()) //.AddInMemoryClients(Config.GetClients(Configuration.GetSection("ConfigSettings").Get<ConfigSettingsBase>())); .AddConfigurationStore(options => { options.ConfigureDbContext = b => b.UseSqlServer(cns, sql => sql.MigrationsAssembly(migrationsAssembly)); }).AddOperationalStore(options => { options.ConfigureDbContext = b => b.UseSqlServer(cns, sql => sql.MigrationsAssembly(migrationsAssembly)); }); //Configurations services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.Configure <ConfigConnectionStringBase>(Configuration.GetSection("ConfigConnectionString")); //Container DI services.AddScoped <CurrentUser>(); services.AddTransient <IUserCredentialServices, UserCredentialServices>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.AddSingleton <IConfiguration>(Configuration); services.AddLogging(loggingBuilder => { loggingBuilder.AddConfiguration(Configuration.GetSection("Logging")); loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); }); services.AddAuthentication() .AddGoogle(options => { options.ClientId = "857854978384-sv33ngtei50k8fn5ea37rcddo08n0ior.apps.googleusercontent.com"; options.ClientSecret = "x1SWT89gyn5LLLyMNFxEx_Ss"; }); // Add cross-origin resource sharing services Configurations var sp = services.BuildServiceProvider(); var configuration = sp.GetService <IOptions <ConfigSettingsBase> >(); Cors.Enable(services, configuration.Value.ClientAuthorityEndPoint.ToArray()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ConfigureAppSettings(services); DependencyInjection.ConfigureServices(services, Configuration); Cors.ConfigureServices(services); Authentication.ConfigureServices(services, Configuration); MVC.ConfigureServices(services); SPA.ConfigureServices(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Camelcase para json services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); }); services.AddDbContext <DbContextSeed>( options => options.UseSqlServer( Configuration .GetSection("ConfigConnectionString:Default").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Seed").Value; options.InstanceName = "Seed"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); services.AddSingleton(new EnviromentInfo { RootPath = this._env.ContentRootPath }); // Config AuthorityEndPoint SSO services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration.GetSection("ConfigSettings:AuthorityEndPoint").Value; options.RequireHttpsMetadata = false; options.ApiName = "ssosa"; }); // Add cross-origin resource sharing services Configurations Cors.Enable(services); // Add application services. ConfigContainerSeed.Config(services); // Add framework services. services.AddMvc(options => { options.ModelBinderProviders.Insert(0, new DateTimePtBrModelBinderProvider()); }) .AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new DateTimePtBrConverter()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddTransient <CRUDcliente, CRUDcliente>(); services.AddTransient <CRUDfactura, CRUDfactura>(); services.AddTransient <CRUDproductos, CRUDproductos>(); services.AddTransient <CRUDProductoFacturado, CRUDProductoFacturado>(); services.AddTransient <CRUDPuntoVenta, CRUDPuntoVenta>(); services.AddCors(Cors => Cors.AddPolicy("AllowAllOrigin", builder => { builder.AllowAnyMethod() .AllowAnyOrigin() .AllowAnyHeader(); })); services.AddDbContext <PuntoVentadbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SqlConnection"))); }
public void ConfigureServices(IServiceCollection services) { var cns = Configuration .GetSection("ConfigConnectionString:Default").Value; services.AddIdentityServer(optionsConfig()) .AddSigningCredential(GetRSAParameters()) .AddCustomTokenRequestValidator <ClientCredentialRequestValidator>() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients(Configuration.GetSection("ConfigSettings").Get <ConfigSettingsBase>())); //Configurations services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.Configure <ConfigConnectionStringBase>(Configuration.GetSection("ConfigConnectionString")); //Container DI services.AddScoped <CurrentUser>(); services.AddScoped <IUserCredentialServices, UserCredentialServices>(); services.AddScoped <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.AddScoped <ICustomTokenRequestValidator, ClientCredentialRequestValidator>(); services.AddSingleton <IConfiguration>(Configuration); services.AddLogging(loggingBuilder => { loggingBuilder.AddConfiguration(Configuration.GetSection("Logging")); loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); }); services.AddAuthentication() .AddGoogle(options => { options.ClientId = "857854978384-sv33ngtei50k8fn5ea37rcddo08n0ior.apps.googleusercontent.com"; options.ClientSecret = "x1SWT89gyn5LLLyMNFxEx_Ss"; }); // Add cross-origin resource sharing services Configurations var sp = services.BuildServiceProvider(); var configuration = sp.GetService <IOptions <ConfigSettingsBase> >(); Cors.Enable(services, configuration.Value.ClientAuthorityEndPoint.ToArray()); services.AddMvc(); }
public void Configuration(IAppBuilder app) { app.Use <LogApiCalls>(); app.UseCors(Cors.GetDefaultCorsOptions()); var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); var jsonMediaTypeFormatter = config.Formatters.JsonFormatter; jsonMediaTypeFormatter.SerializerSettings = JsonNetSerializerSettings.CreateDefault(); config.Formatters.Remove(config.Formatters.XmlFormatter); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); config.MessageHandlers.Add(new CachingHttpHandler()); app.UseWebApi(config); }
private static Action <CorsPolicyBuilder> CorsPolicyBuilder(Cors config) { //TODO implement an url based cors policy rather than global or per controller return(builder => { if (config.AllowCredentials) { builder.AllowCredentials(); } else { builder.DisallowCredentials(); } builder.WithOrigins(config.AllowedOrigins) .WithMethods(config.AllowedMethods) .WithHeaders(config.AllowedHeaders) .WithExposedHeaders(config.ExposedHeaders) .SetPreflightMaxAge(TimeSpan.FromSeconds(config.MaxAge)); }); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DbContextCore>(options => options.UseSqlServer(Configuration.GetSection("EFCoreConnStrings:Core").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Core").Value; options.InstanceName = "Core"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); Cors.Enable(services); ConfigContainerCore.Config(services); services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new Common.API.Converters.DateTimePtBrConverter()); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, Cors cors) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } ConfigureCors(app, cors); ConfigureLogger(); app.UseMvc(); app.UseGraphQL <ISchema>(); if (env.IsDevelopment()) { app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { Path = "/ui/playground" }); } }
public void ConfigureServices(IServiceCollection services) { var cnsCalemas = Configuration.GetSection("EFCoreConnStrings:Calemas").Value; services.AddDbContext <DbContextCore>(options => options.UseSqlServer(cnsCalemas)); services.AddIdentityServer() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddSigningCredential(GetRSAParameters()); services.AddScoped <CurrentUser>(); services.AddTransient <IColaboradorRepository, ColaboradorRepository>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); Cors.Enable(services); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.Configure <ConfigConnectionStringBase>(Configuration.GetSection("ConfigConnectionString")); services.AddSingleton <IConfiguration>(Configuration); var authorityEndPoint = Configuration.GetSection("ConfigSettings:AuthorityEndPoint").Value; services.AddAuthentication(options => { options.DefaultScheme = "Cookies"; options.DefaultChallengeScheme = "oidc"; }) .AddCookie("Cookies") .AddOpenIdConnect("oidc", options => { options.SignInScheme = "Cookies"; options.Authority = authorityEndPoint; options.RequireHttpsMetadata = false; options.ClientId = "hangfire-dash"; options.SaveTokens = true; }); // Add cross-origin resource sharing services Configurations Cors.Enable(services); var connectionString = Configuration.GetSection("ConfigConnectionString:Default").Value; //services.AddHangfire(x => x.UseSqlServerStorage(connectionString)); services.AddHangfire(x => x.UseMemoryStorage()); // Add application services. ConfigContainer.Config(services); services.AddMvc(); }
// 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.UseAuthentication(); // app.UseHttpsRedirection(); app.UseCors(Cors => Cors.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void ConfigureServices(IServiceCollection services) { var cns = Configuration .GetSection("ConfigConnectionString:Default").Value; services.AddIdentityServer() //.AddSigningCredential(GetRSAParameters()) .AddTemporarySigningCredential() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients(Configuration.GetSection("ConfigSettings").Get <ConfigSettingsBase>())); //for clarity of the next piece of code services.AddScoped <CurrentUser>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); // Add cross-origin resource sharing services Configurations Cors.Enable(services); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Camelcase para json services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); }); services.AddDbContext <DbContextSeed>( options => options.UseSqlServer( Configuration .GetSection("ConfigConnectionString:Default").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Seed").Value; options.InstanceName = "Seed"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); // Add cross-origin resource sharing services Configurations Cors.Enable(services); // Add application services. ConfigContainerSeed.Config(services); // Add framework services. services.AddMvc(options => { options.ModelBinderProviders.Insert(0, new DateTimePtBrModelBinderProvider()); }) .AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new DateTimePtBrConverter()); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseDeveloperExceptionPage(); app.UseHsts(); } app.UseHttpsRedirection(); Cors.Configure(app, env); Authentication.Configure(app, env); MVC.Configure(app, env); SPA.Configure(app, env); StaticFiles.Configure(app, env); }
protected void Application_BeginRequest() { Cors.AddCorsHeadersIfAllowed(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DbContextTarget>( options => options.UseSqlServer( Configuration .GetSection("EFCoreConnStrings:Target").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Target").Value; options.InstanceName = "Target"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); // Add cross-origin resource sharing services Configurations Cors.Enable(services); // Add application services. ConfigContainerTarget.Config(services); // Add framework services. services.AddMvc(options => { options.ModelBinderProviders.Insert(0, new DateTimePtBrModelBinderProvider()); }); services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new DateTimePtBrConverter()); }); // Configurando o serviço de documentação do Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Target Pendencias", Version = "v1", Description = "API Target Pendencias", Contact = new Contact { Name = "Wilson Santos", Url = "http://targetsoftware.com.br" }, }); var caminhoAplicacao = PlatformServices.Default.Application.ApplicationBasePath; var nomeAplicacao = PlatformServices.Default.Application.ApplicationName; var caminhoXmlDoc = Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml"); c.IncludeXmlComments(caminhoXmlDoc); //c.AddSecurityDefinition("oauth2", new OAuth2Scheme //{ // Type = "oauth2", // Flow = "implicit", // AuthorizationUrl = "http://localhost:4000/connect/authorize", // Scopes = new Dictionary<string, string> // { // { "ssosa", "ssosa" }, // } //}); //c.OperationFilter<SecurityRequirementsOperationFilter>(); c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\"", Name = "Authorization", In = "header", Type = "apiKey" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.WriteIndented = false; options.JsonSerializerOptions.AllowTrailingCommas = true; options.JsonSerializerOptions.Converters.Add(new StringJsonConverter()); }); services.AddDbContext <DbContextSeed>( options => options.UseSqlServer( Configuration .GetSection("ConfigConnectionString:Default").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("ConfigCache:Default").Value; options.InstanceName = "Seed"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.Configure <ConfigStorageConnectionStringBase>(Configuration.GetSection("ConfigStorage")); services.AddSingleton <IConfiguration>(Configuration); services.AddSingleton(new EnviromentInfo { RootPath = this._env.ContentRootPath }); services.AddLogging(loggingBuilder => { loggingBuilder.AddConfiguration(Configuration.GetSection("Logging")); loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); }); // Config AuthorityEndPoint SSO services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration.GetSection("ConfigSettings:AuthorityEndPoint").Value; options.RequireHttpsMetadata = false; options.ApiName = "ssosa"; }); // Add cross-origin resource sharing services Configurations var sp = services.BuildServiceProvider(); var configuration = sp.GetService <IOptions <ConfigSettingsBase> >(); Cors.Enable(services, configuration.Value.ClientAuthorityEndPoint.ToArray()); services.AddAutoMapper(AutoMapperConfigSeed.RegisterMappings()); // Add application services. ConfigContainerSeed.Config(services); // Add framework services. //services.AddMvc(options => //{ // options.ModelBinderProviders.Insert(0, new DateTimePtBrModelBinderProvider()); // options.ModelBinderProviders.Insert(1, new NumberModelBinderProvider()); //}); //.AddNewtonsoftJson(); // TODO : MIGRAÇÃO PROBLEMA 02 //.AddJsonOptions(options => //{ // options.SerializerSettings.Converters.Add(new DateTimePtBrConverter()); // options.SerializerSettings.Converters.Add(new DecimalPtBrConverter()); //}); //Policys services.AddAuthorizationPolicy(ProfileCustom.Define); // Configurando o serviço do Swagger //services.AddSwaggerGen(c => //{ // c.SwaggerDoc("v1", // new Info // { // Title = "Target.Intranet", // Version = "v1", // Description = "Target.Intranet", // }); // var caminhoAplicacao = PlatformServices.Default.Application.ApplicationBasePath; // var nomeAplicacao = PlatformServices.Default.Application.ApplicationName; // var caminhoXmlDoc = Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml"); // c.IncludeXmlComments(caminhoXmlDoc); // c.AddSecurityDefinition("oauth2", new OAuth2Scheme // { // Type = "oauth2", // Flow = "implicit", // AuthorizationUrl = "http://localhost:4000/connect/authorize", // Scopes = new Dictionary<string, string> // { // { "ssosa", "ssosa" }, // } // }); // c.OperationFilter<AuthorizeCheckOperationFilter>(); //}); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Camelcase para json services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); }); services.AddDbContext <DbContextSeed>( options => options.UseSqlServer( Configuration .GetSection("ConfigConnectionString:Default").Value)); services.AddDistributedRedisCache(options => { options.Configuration = Configuration.GetSection("RedisConnStrings:Seed").Value; options.InstanceName = "Seed"; }); services.Configure <ConfigSettingsBase>(Configuration.GetSection("ConfigSettings")); services.AddSingleton <IConfiguration>(Configuration); services.AddSingleton(new EnviromentInfo { RootPath = this._env.ContentRootPath }); // Config AuthorityEndPoint SSO services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration.GetSection("ConfigSettings:AuthorityEndPoint").Value; options.RequireHttpsMetadata = false; options.ApiName = "ssosa"; }); // Add cross-origin resource sharing services Configurations var sp = services.BuildServiceProvider(); var configuration = sp.GetService <IOptions <ConfigSettingsBase> >(); Cors.Enable(services, configuration.Value.ClientAuthorityEndPoint.ToArray()); // Add application services. ConfigContainerSeed.Config(services); // Add framework services. services.AddMvc(options => { options.ModelBinderProviders.Insert(0, new DateTimePtBrModelBinderProvider()); }) .AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new DateTimePtBrConverter()); }); //Policys services.AddAuthorizationPolicy(ProfileCustom.Define); // Configurando o serviço do Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Seed", Version = "v1", Description = "Seed", }); var caminhoAplicacao = PlatformServices.Default.Application.ApplicationBasePath; var nomeAplicacao = PlatformServices.Default.Application.ApplicationName; var caminhoXmlDoc = Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml"); c.IncludeXmlComments(caminhoXmlDoc); c.AddSecurityDefinition("oauth2", new OAuth2Scheme { Type = "oauth2", Flow = "implicit", AuthorizationUrl = "http://localhost:4000/connect/authorize", Scopes = new Dictionary <string, string> { { "ssosa", "ssosa" }, } }); c.OperationFilter <AuthorizeCheckOperationFilter>(); }); }