-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (44 loc) · 1.41 KB
/
Program.cs
File metadata and controls
56 lines (44 loc) · 1.41 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
49
50
51
52
53
54
55
using CloudinaryDotNet;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddControllers(); // ✅ Bắt buộc để dùng MapControllers()
// Đăng ký CloudinarySettings từ appsettings.json
builder.Services.Configure<CloudinarySettings>(
builder.Configuration.GetSection("CloudinarySettings"));
// Đăng ký Cloudinary để inject vào controller (nếu muốn dùng DI)
builder.Services.AddSingleton(sp =>
{
var settings = sp.GetRequiredService<IOptions<CloudinarySettings>>().Value;
var account = new Account(settings.CloudName, settings.ApiKey, settings.ApiSecret);
return new Cloudinary(account);
});
// Đăng ký Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CloudinaryDemo API", Version = "v1" });
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
if (app.Environment.IsProduction())
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.MapControllers();
app.Run();