-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStartup.cs
More file actions
48 lines (40 loc) · 1.25 KB
/
Startup.cs
File metadata and controls
48 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using BuildRestApiNetCore.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
namespace BuildRestApiNetCore
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ProductContext>(opt => opt.UseInMemoryDatabase("Products"));
services.AddControllers().AddNewtonsoftJson();
services.AddApiVersioning(opt => opt.ReportApiVersions = true);
services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Products",
Description = "The ultimate e-commerce store for all your needs",
Version = "v1"
}));
}
public void Configure(IApplicationBuilder app)
{
app.UseSwagger();
app.UseSwaggerUI(opt => opt.SwaggerEndpoint("/swagger/v1/swagger.json", "Products v1"));
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}