Skip to content

Commit 49c6c8b

Browse files
committed
Readme updated
1 parent 436efbc commit 49c6c8b

File tree

1 file changed

+101
-5
lines changed

1 file changed

+101
-5
lines changed

README.md

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,101 @@
1-
# MongoDb.Asp.ConfigurationProvider
2-
A Simple ASP5 configuration provider for MongoDb. To Install following in PM Console
3-
```
4-
Install-Package MongoDb.Asp.ConfigurationProvider
5-
```
1+
# .Net Core configuration provider for MongoDb
2+
3+
*Please note, I have moved the project to .net core latest version provide. There are some improvements and known issues which are in progress. Please raise an issue in case of any help needed. PRs are welcome*
4+
5+
# Getting Started
6+
7+
1. Install the nuget package:
8+
9+
```c#
10+
Install-Package MongoDb.Asp.ConfigurationProvider
11+
```
12+
13+
14+
15+
2. Update the Program.cs file in web app to use the the new configuration provider.
16+
17+
18+
```c#
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureAppConfiguration(ConfigureMongoConfiguration) //THIS LINE IS ADDED TO ADD DELEGATE
22+
.ConfigureWebHostDefaults(webBuilder =>
23+
{
24+
webBuilder.UseStartup<Startup>();
25+
});
26+
27+
//USE THE FOLLOWING METHOD TO ADD PROVIDER.
28+
private static void ConfigureMongoConfiguration(HostBuilderContext arg1, IConfigurationBuilder configurationBuilder)
29+
{
30+
configurationBuilder.AddMongoDbConfiguration(MongoDbConfigOptions.GetOptionsForAllKeysAllDocuments(
31+
@"mongodb://<CONNECTION_STRING>",
32+
"myconfigdb", "settings"));
33+
}
34+
```
35+
36+
3. Mongo Document used for holding configuration / settings
37+
38+
```json
39+
{
40+
"_id": {
41+
"$oid": "5f0e087f575f22cece93ac8d"
42+
},
43+
"key1": "value1",
44+
"key9":"val2",
45+
"environment":"dev",
46+
"key3":"val3",
47+
"key2":{
48+
"a1":"a3"
49+
}
50+
}
51+
```
52+
53+
54+
55+
**PS: Please refer the provided TestWebApp to view usage.**
56+
57+
58+
59+
## Configuration Builders
60+
61+
Following four methods are provided currently to load different configurations. "_id" is ignored by default.
62+
63+
1. AllKeys - All Documents - (MongoDbConfigOptions.GetOptionsForAllKeysAllDocuments()) - Use this to read all the keys from all the documents in a collection
64+
2. Defined Keys - All Documents (MongoDbConfigOptions.GetOptionsForDefinedKeysAllDocuments) - Use this method to load specific set of keys (named keys) from all the documents in a collection.
65+
3. All Keys - Filtered Documents (MongoDbConfigOptions.GetOptionsForAllKeysFilteredDocuments) - Use this method to load all the keys from filtered document. Filter can be applied for a single set of key value pair. Example could be to look for env variables.
66+
4. Defined Keys - Filtered Documents (MongoDbConfigOptions.GetOptionsForDefinedKeysFilteredDocument) - Use this method to load specific set of keys from filtered document. Filter can be applied for a single set of key value pair. Example could be to look for env variables.
67+
68+
69+
70+
71+
72+
## Assumptions / Known Issues
73+
74+
1. "_id" field is ignored by difficult. This is on-purpose.
75+
2. Nested Keys and child sections are currently not supported.
76+
77+
78+
79+
# Examples Usage
80+
81+
82+
83+
```c#
84+
private static void ConfigureMongoConfiguration(HostBuilderContext arg1, IConfigurationBuilder configurationBuilder)
85+
{
86+
configurationBuilder.AddMongoDbConfiguration(MongoDbConfigOptions.GetOptionsForAllKeysAllDocuments(
87+
@"mongodb://<CONNECTION_STRING>",
88+
"myconfigdb", "settings"));
89+
configurationBuilder.AddMongoDbConfiguration(MongoDbConfigOptions.GetOptionsForDefinedKeysAllDocuments(
90+
@"mongodb://<CONNECTION_STRING>",
91+
"myconfigdb", "settings","key2","key3"));
92+
93+
configurationBuilder.AddMongoDbConfiguration(MongoDbConfigOptions.GetOptionsForAllKeysFilteredDocuments(
94+
@"mongodb://<CONNECTION_STRING>",
95+
"myconfigdb", "settings", "environment", "qa"));
96+
97+
configurationBuilder.AddMongoDbConfiguration(MongoDbConfigOptions.GetOptionsForDefinedKeysFilteredDocument(
98+
@"mongodb://<CONNECTION_STRING>",
99+
"myconfigdb", "settings", "environment", "dev", "key1", "key2", "key9"));
100+
}
101+
```

0 commit comments

Comments
 (0)