// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); // Create the container builder. var builder = new ContainerBuilder(); builder.Populate(services); IOC.Builder = builder; ApplicationContainer = IOC.Start(); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); return(new AutofacServiceProvider(ApplicationContainer)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.AddAuthentication(IISDefaults.AuthenticationScheme); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddMemoryCache(); //services.Configure<IISOptions>(o => //{ // o.ForwardClientCertificate = false; //}); string[] urls = { "http://localhost:3000", "http://localhost:3001", "http://localhost:3002", "http://dev-isp.CTTPB.com.br", "http://homolog-isp.CTTPB.com.br", "http://isp.CTTPB.com.br", "http://localhost:8080", "http://ncp110:9811", "http://ncp110n:9815" }; services.AddCors(option => { option.AddPolicy("AllowAll", policy => policy.WithOrigins(urls) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); }); services.AddMvc(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }) .AddJsonOptions(options => { var settings = options.SerializerSettings; settings.NullValueHandling = NullValueHandling.Ignore; settings.Formatting = Formatting.Indented; settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; settings.DateTimeZoneHandling = DateTimeZoneHandling.Local; // dont mess with case of properties if (settings.ContractResolver is DefaultContractResolver resolver) { resolver.NamingStrategy = null; } }); services.Configure <IntegracaoMassaConfig>(Configuration.GetSection(nameof(IntegracaoMassaConfig))); services.Configure <IntegracaoToledoConfig>(Configuration.GetSection(nameof(IntegracaoToledoConfig))); services.Configure <BalancaFerroviariaGenericConfig>(Configuration.GetSection(nameof(BalancaFerroviariaGenericConfig))); // Create the container builder. var builder = new ContainerBuilder(); builder.Populate(services); IOC.Builder = builder; ApplicationContainer = IOC.Start(); //var _permissaoAcessoRepository = IOC.Container.Resolve<IPermissaoAcessoRepository>(); //var acessos = _permissaoAcessoRepository.GetAll(); // Create the IServiceProvider based on the container. return(new AutofacServiceProvider(ApplicationContainer)); }