Exemplo n.º 1
0
        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddInstance<IConfiguration>(Configuration);
            services.AddCustomBindings(Configuration);

            services.AddMvc().Configure<MvcOptions>(options =>
            {
                options.OutputFormatters.OfType<JsonOutputFormatter>()
                       .First()
                       .SerializerSettings
                       .ContractResolver = new CamelCasePropertyNamesContractResolver();
            });

            // CORS
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Core.CorsPolicy();
            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.ConfigureCors(x => x.AddPolicy("mypolicy", policy));

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();
        }