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 ;
12using SimpleInventoryManagementSystem . Controller ;
23using SimpleInventoryManagementSystem . DAO ;
4+ using SimpleInventoryManagementSystem . Domain ;
35using SimpleInventoryManagementSystem . Interfaces ;
46using 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}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments