-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (46 loc) · 1.41 KB
/
Program.cs
File metadata and controls
57 lines (46 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
56
57
using ExternalApiBackend.Repositories;
using ExternalApiBackend.Services;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Optional: Enable CORS
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
// -------------------------------------------
// 1) Register a typed HttpClient for MyRepository
builder.Services.AddHttpClient<IMyRepository, MyRepository>();
// 2) Register other services
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IExternalApiService, ExternalApiService>();
// Controllers, endpoints, swagger
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "External API Backend",
Version = "v1"
});
});
// Build the app
var app = builder.Build();
// Only use Swagger in Development (optional)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("/swagger/v1/swagger.json", "External API Backend v1"));
}
// Apply CORS policy
app.UseCors("AllowAll");
// For ASP.NET Core 6+ minimal hosting, routing is automatically enabled
app.UseAuthorization();
// Map controllers
app.MapControllers();
// Run the app
app.Run();