-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (27 loc) · 1.04 KB
/
Program.cs
File metadata and controls
41 lines (27 loc) · 1.04 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
using Microsoft.EntityFrameworkCore;
using RepositoryTutorial.Infrastructure;
using RepositoryTutorial.Services.ProductService;
var builder = WebApplication.CreateBuilder(args);
// add services to the container.
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddEndpointsApiExplorer();
// register automapper
builder.Services.AddAutoMapper(typeof(MappingProfiles));
// register db context
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// register your repository
builder.Services.AddScoped<IRepositoryAsync, RepositoryAsync>();
// register app services
builder.Services.AddTransient<IProductService, ProductService>();
var app = builder.Build();
// configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
// NOTE: To test the API use the postman collection included in this repo
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();