File tree Expand file tree Collapse file tree 2 files changed +18
-35
lines changed Expand file tree Collapse file tree 2 files changed +18
-35
lines changed Original file line number Diff line number Diff line change
1
+ using MongoDB . Driver ;
1
2
using SimpleInventoryManagementSystem . Controller ;
2
3
using SimpleInventoryManagementSystem . DAO ;
4
+ using SimpleInventoryManagementSystem . Domain ;
3
5
using SimpleInventoryManagementSystem . Interfaces ;
4
6
using SimpleInventoryManagementSystem . Repository ;
5
7
@@ -9,6 +11,21 @@ public static class Configuration
9
11
{
10
12
public static IUserController BuildUserController ( )
11
13
{
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 ) ;
13
30
}
14
31
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments