How to read values from appsetting through IOptions in .NET ?
๐ก ๐๐จ๐ฐ ๐ญ๐จ ๐ซ๐๐๐ ๐ฏ๐๐ฅ๐ฎ๐๐ฌ ๐๐ซ๐จ๐ฆ ๐๐ฉ๐ฉ๐ฌ๐๐ญ๐ญ๐ข๐ง๐ .๐ฃ๐ฌ๐จ๐ง ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ.
๐ก ๐๐จ๐ฐ ๐ญ๐จ ๐ซ๐๐๐ ๐ฏ๐๐ฅ๐ฎ๐๐ฌ ๐๐ซ๐จ๐ฆ ๐๐ฉ๐ฉ๐ฌ๐๐ญ๐ญ๐ข๐ง๐ .๐ฃ๐ฌ๐จ๐ง ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ.
๐ฏ ๐๐ญ๐๐ฉ ๐ย : Define your properties in key-value format in json file.
๐ฏ ๐๐ญ๐๐ฉ ๐ย : Make a class with same propertiesย , make sure names should be exactly same.
๐ฏ ๐๐ญ๐๐ฉ ๐ย : Inject configurations in Program.cs (Forย .NET 6) and in ConfigureServices Method (Below thanย .NET 6)
๐ฏ ๐๐ญ๐๐ฉ ๐ย : Now Inject class containing properties in constructor of your desired class where you need.
If you like my work you can help me in growing through following ways
Subscribe my Weeklyย .NET Newsletter where I would be publishing one tip on C#/.NET on weekly basis.
You can Buy a Coffee for me.