-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
34 lines (23 loc) · 958 Bytes
/
Program.cs
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
using MainApp.Data.MusicRepo;
using MainApp.Models;
using MongoDB.Driver;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
// Add connection string
builder.Services.Configure<MongoDbSettings>(builder.Configuration.GetSection("MongoDBSettings"));
// Register mongoDb configuration as a singleton object
builder.Services.AddSingleton<IMongoDatabase>(options=>{
var settings= builder.Configuration.GetSection("MongoDBSettings").Get<MongoDbSettings>();
var client = new MongoClient(settings.ConnectionString);
return client.GetDatabase(settings.DatabaseName);
});
// Register music service
builder.Services.AddSingleton<IMusicService, MusicService>();
// Register autoMapper
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();