Skip to content

Commit 517b975

Browse files
committed
Replace in-memory with bson product dao
1 parent 3257b89 commit 517b975

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

Configuration.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using MongoDB.Driver;
12
using SimpleInventoryManagementSystem.Controller;
23
using SimpleInventoryManagementSystem.DAO;
4+
using SimpleInventoryManagementSystem.Domain;
35
using SimpleInventoryManagementSystem.Interfaces;
46
using SimpleInventoryManagementSystem.Repository;
57

@@ -9,6 +11,21 @@ public static class Configuration
911
{
1012
public static IUserController BuildUserController()
1113
{
12-
return new UserController(new ProductRepository(new MemoryProductDao()));
14+
return new UserController(new ProductRepository(BuildProductDao()));
15+
}
16+
17+
private static IProductDao BuildProductDao()
18+
{
19+
var connectionString = Environment.GetEnvironmentVariable("MONGODB_CONNECTION_STRING");
20+
if (connectionString == null)
21+
{
22+
throw new IOException("MONGODB_CONNECTION_STRING environmental variable was not found");
23+
}
24+
25+
var client = new MongoClient(connectionString);
26+
var database = client.GetDatabase("Inventory");
27+
var productsCollection = database.GetCollection<Product>("Products");
28+
29+
return new BsonProductDao(productsCollection);
1330
}
1431
}

src/DAO/MemoryProductDao.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)