Skip to content

Commit 3044237

Browse files
committed
Update Startup.cs
code cleanup
1 parent bbe6e0a commit 3044237

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

Supermarket/Startup.cs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using AutoMapper;
2-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
32
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.HttpOverrides;
44
using Microsoft.AspNetCore.Mvc;
5-
using Microsoft.EntityFrameworkCore;
65
using Microsoft.Extensions.Configuration;
76
using Microsoft.Extensions.DependencyInjection;
8-
using Supermarket.Domain.Services;
9-
using Supermarket.Domain.Services.Contracts;
10-
using Supermarket.Persistent.Context;
11-
using Supermarket.Persistent.Contracts;
12-
using Supermarket.Persistent.Repositories;
7+
using Newtonsoft.Json.Serialization;
8+
using Supermarket.Extensions;
9+
using Swashbuckle.AspNetCore.Swagger;
1310

1411
namespace Supermarket
1512
{
@@ -25,17 +22,25 @@ public Startup(IConfiguration configuration)
2522
// This method gets called by the runtime. Use this method to add services to the container.
2623
public void ConfigureServices(IServiceCollection services)
2724
{
28-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
25+
services.ConfigureCors();
2926

30-
services.AddDbContext<RepositoryContext>(options =>
27+
services.ConfigureIISIntegration();
28+
29+
services.ConfigureMSSQLContext(Configuration);
30+
31+
services.ConfigureRepositoryWrapper();
32+
33+
services.ConfigureServicesWrapper();
34+
35+
services.AddMvc().AddJsonOptions(options =>
3136
{
32-
options.UseInMemoryDatabase("supermarket-api-in-memory");
33-
});
37+
//Force Camel Case to JSON
38+
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
39+
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
3440

35-
services.AddScoped<IRepositoryWrapper, RepositoryWrapper>();
36-
services.AddScoped<IServiceWrapper, ServiceWrapper>();
41+
services.ConfigureAutoMapper();
3742

38-
services.AddAutoMapper();
43+
services.ConfigureSwagger();
3944
}
4045

4146
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -52,7 +57,27 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5257
}
5358

5459
app.UseHttpsRedirection();
60+
61+
//CORS configuration has beend added to the application pipeline
62+
app.UseCors("CorsPolicy");
63+
64+
app.UseForwardedHeaders(new ForwardedHeadersOptions
65+
{
66+
ForwardedHeaders = ForwardedHeaders.All
67+
});
68+
69+
app.UseStaticFiles();
5570
app.UseMvc();
71+
72+
// Enable middleware to serve generated Swagger as a JSON endpoint.
73+
app.UseSwagger();
74+
75+
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
76+
// specifying the Swagger JSON endpoint.
77+
app.UseSwaggerUI(c =>
78+
{
79+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Supermarket API V1");
80+
});
5681
}
5782
}
5883
}

0 commit comments

Comments
 (0)