Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(opts =>
            {
                var corsMw = new CorsMiddleware(opts);
                corsMw.AddAllowAllOriginsPolicy();
            });
            services.AddMvc(
                setupAction =>
            {
                setupAction.ReturnHttpNotAcceptable = true;
                setupAction.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter());
                setupAction.InputFormatters.Add(new XmlDataContractSerializerInputFormatter());
            });
            services.AddScoped <IUsersService>(provider => new UsersService(new DateTimeProvider(), new UsersRepository()));
            services.AddScoped <IEventsService>(provider => new EventsService(new EventsRepository()));

            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddScoped <IUrlHelper, UrlHelper>(implementationFactory =>
            {
                var actionContext = implementationFactory.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Example API", Version = "v1"
                });
                c.OperationFilter <ExamplesOperationFilter>();
            });
        }