aboutsummaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'Backend')
-rw-r--r--Backend/Api/Api/Api.csproj3
-rw-r--r--Backend/Api/Api/Database/DatabaseConnection.cs10
-rw-r--r--Backend/Api/Api/Interfaces/IDatabaseConnection.cs8
-rw-r--r--Backend/Api/Api/Program.cs14
-rw-r--r--Backend/Api/Api/appsettings.json8
5 files changed, 40 insertions, 3 deletions
diff --git a/Backend/Api/Api/Api.csproj b/Backend/Api/Api/Api.csproj
index 8732b1d..f8d2732 100644
--- a/Backend/Api/Api/Api.csproj
+++ b/Backend/Api/Api/Api.csproj
@@ -7,14 +7,13 @@
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Models\" />
- <Folder Include="Interfaces\" />
- <Folder Include="Database\" />
<Folder Include="Services\" />
</ItemGroup>
diff --git a/Backend/Api/Api/Database/DatabaseConnection.cs b/Backend/Api/Api/Database/DatabaseConnection.cs
new file mode 100644
index 0000000..560eaee
--- /dev/null
+++ b/Backend/Api/Api/Database/DatabaseConnection.cs
@@ -0,0 +1,10 @@
+using Api.Interfaces;
+
+namespace Api.Database
+{
+ public class DatabaseConnection : IDatabaseConnection
+ {
+ public string ConnectionString { get; set; } = String.Empty;
+ public string DatabaseName { get; set; } = String.Empty;
+ }
+}
diff --git a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs
new file mode 100644
index 0000000..ca5e320
--- /dev/null
+++ b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs
@@ -0,0 +1,8 @@
+namespace Api.Interfaces
+{
+ public interface IDatabaseConnection
+ {
+ string ConnectionString { get; set; }
+ string DatabaseName { get; set; }
+ }
+}
diff --git a/Backend/Api/Api/Program.cs b/Backend/Api/Api/Program.cs
index df2434c..2dfd84d 100644
--- a/Backend/Api/Api/Program.cs
+++ b/Backend/Api/Api/Program.cs
@@ -1,7 +1,21 @@
+using Api.Database;
+using Api.Interfaces;
+using Microsoft.Extensions.Options;
+using MongoDB.Driver;
+
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
+builder.Services.Configure<DatabaseConnection>(
+ builder.Configuration.GetSection("DatabaseSettings"));
+
+builder.Services.AddSingleton<IDatabaseConnection>(sp =>
+ sp.GetRequiredService<IOptions<DatabaseConnection>>().Value);
+
+builder.Services.AddSingleton<IMongoClient>(s =>
+ new MongoClient(builder.Configuration.GetValue<string>("DatabaseSettings:ConnectionString")));
+
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
diff --git a/Backend/Api/Api/appsettings.json b/Backend/Api/Api/appsettings.json
index 10f68b8..c2cbe28 100644
--- a/Backend/Api/Api/appsettings.json
+++ b/Backend/Api/Api/appsettings.json
@@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
- "AllowedHosts": "*"
+ "AllowedHosts": "*",
+ "DatabaseSettings": {
+
+ "ConnectionString": "mongodb://127.0.0.1:27017/",
+ "DatabaseName": "Odyssey"
+
+ }
}