Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCaching();
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            services.AddControllers(
                setupoptions =>
            {
                setupoptions.ReturnHttpNotAcceptable = true;
                setupoptions.CacheProfiles.Add("90SecondsCacheProfile",
                                               new CacheProfile {
                    Duration = 90
                });
            })
            .AddNewtonsoftJson(setupAction => {
                setupAction.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();
            })
            .AddXmlDataContractSerializerFormatters();
            services.AddCors(
                Options => {
                Options.AddDefaultPolicy(Builder => Builder.WithOrigins("http://localhost:3000"));
                Options.AddPolicy("mypolicy", Builder => Builder.WithOrigins("http://192.168.1.38:3000"));
            }

                );

            services.AddScoped <IBandAlbumnRepo, BandAlbumnRepo>();
            services.AddScoped <IpropertyValidationService, propertyValidationService>();
            services.AddScoped <IPropertyMappingService, PropertyMappingService>();
            services.AddDbContext <DataContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"));
            });
        }
Beispiel #2
0
 // 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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
 }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddCors(Options =>
            {
                Options.AddDefaultPolicy(builder =>
                {
                    builder.WithOrigins("*");
                    builder.WithMethods("GET", "POST", "PUT", "DELETE");
                });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            // Configure CORS to accept origins with default SSL port 44362 configured in launchSettings.json
            // and from port 5001 which is the default port if you run the application from command line
            services.AddCors(Options => {
                Options.AddDefaultPolicy(builder =>
                {
                    builder.WithOrigins("https://localhost:44362", "https://localhost:5001")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddTransient <ICheckoutService, CheckoutService>();
            services.AddTransient <ICheckoutRepository, CheckoutRepository>();

            services.AddTransient <IProductsService, ProductsService>();
            services.AddTransient <IProductsRepository, ProductsRepository>();

            services.AddTransient <IDiscountsRepository, DiscountsRepository>();

            // Configure API documentation with Swagger
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "Supermarket Pricing Kata API",
                    Version     = "v1",
                    Description = "Visualize and interact with the API's resources",
                });
            });
        }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <ShopContext>(options => options.UseInMemoryDatabase("Shop"));
     services.AddControllers();
     services.AddCors(Options =>
     {
         Options.AddDefaultPolicy(builder =>
         {
             builder.WithOrigins("https://localhost:44364").AllowAnyHeader().AllowAnyMethod();
         });
     });
     services.AddApiVersioning(Options =>
     {
         Options.ReportApiVersions = true;
         Options.DefaultApiVersion = new ApiVersion(1, 0);
         Options.AssumeDefaultVersionWhenUnspecified = true;
         Options.ApiVersionReader = new HeaderApiVersionReader("X-API-Version");
     });
     services.AddVersionedApiExplorer(
         options => options.GroupNameFormat = "'v'VVV");
     services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>();
     services.AddSwaggerGen(options => options.OperationFilter <SwaggerDefaultValues>());
 }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     services.AddCors(Options => Options.AddDefaultPolicy(builder => builder.WithOrigins("http://localhost:44386").AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod()));
 }