Hi, @EuroEager2008
This code might help you!
Please let me know if there's anything else I can assist you with.
{
"MyConfig": {
"Item1": { "Prop1": 1 },
"Item2": { "Prop1": 2 }
}
}
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
public class ItemClass
{
public int Prop1 { get; set; }
}
public class MyConfig
{
public Dictionary<string, ItemClass> Config { get; set; }
}
//Startup.cs or Program.cs
// ..
services.Configure<MyConfig>(Configuration.GetSection("MyConfig"));
// ..
public class MyController : Controller
{
private readonly MyConfig _myConfig;
public MyController(IOptions<MyConfig> myConfig)
{
_myConfig = myConfig.Value;
}
public IActionResult Index()
{
var item1 = _myConfig.Config["Item1"];
return View();
}
}
In order for this code to work, you need to provide valid JSON files.
As @Thomas Wycichowski said: You will need to adjust
from
{"Item1":{"Prop1"=1}}
to
{"Item1":{"Prop1":1}}
Have a nice day,
Lucas Amorim