| | 1 | | using WebApi.DAO; |
| | 2 | | using WebApi.Services; |
| | 3 | | using SharedObjects.Auth; |
| | 4 | |
|
| 0 | 5 | | var builder = WebApplication.CreateBuilder(args); |
| | 6 | |
|
| | 7 | | // Add services to the container. |
| 0 | 8 | | builder.Services.AddControllers().AddNewtonsoftJson(options => |
| 0 | 9 | | { |
| 0 | 10 | | options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; |
| 0 | 11 | | }); |
| | 12 | | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
| 0 | 13 | | builder.Services.AddEndpointsApiExplorer(); |
| 0 | 14 | | builder.Services.AddSwaggerGen(); |
| | 15 | |
|
| | 16 | | // Register the MongoDbContext |
| 0 | 17 | | builder.Services.AddSingleton<MongoDbContext>(sp => |
| 0 | 18 | | new MongoDbContext( |
| 0 | 19 | | builder.Configuration.GetConnectionString("MongoDb"), |
| 0 | 20 | | "indeklima_db" |
| 0 | 21 | | ) |
| 0 | 22 | | ); |
| 0 | 23 | | builder.Services.AddScoped<ISensorDataService, SensorDataService>(); |
| 0 | 24 | | builder.Services.AddScoped<ISensorDataDAO, SensorDataDAO>(); |
| 0 | 25 | | builder.Services.AddScoped<ISensorGoalService, SensorGoalService>(); |
| 0 | 26 | | builder.Services.AddScoped<ISensorGoalDAO, SensorGoalDAO>(); |
| 0 | 27 | | builder.Services.AddScoped<IIOTControlService, IOTControlService>(); |
| | 28 | |
|
| 0 | 29 | | AuthorizationPolicies.AddAuth(builder); |
| | 30 | |
|
| 0 | 31 | | var app = builder.Build(); |
| | 32 | |
|
| | 33 | | // Configure the HTTP request pipeline. |
| 0 | 34 | | if (app.Environment.IsDevelopment()) |
| 0 | 35 | | { |
| 0 | 36 | | app.UseSwagger(); |
| 0 | 37 | | app.UseSwaggerUI(); |
| 0 | 38 | | } |
| | 39 | |
|
| 0 | 40 | | app.UseCors(x => x |
| 0 | 41 | | .AllowAnyMethod() |
| 0 | 42 | | .AllowAnyHeader() |
| 0 | 43 | | .SetIsOriginAllowed(origin => true) // allow any origin |
| 0 | 44 | | .AllowCredentials()); |
| | 45 | |
|
| 0 | 46 | | app.UseHttpsRedirection(); |
| | 47 | |
|
| 0 | 48 | | app.UseAuthorization(); |
| | 49 | |
|
| 0 | 50 | | app.MapControllers(); |
| | 51 | |
|
| 0 | 52 | | app.Run(); |