How can I create a global variable in an ASP.NET Core Web API application? In ASP.NET MVC, I could do it like:
Application["<variableName>"] = <value>
I tried the same in my web API application, but was unable to find an equivalent for this. I saw some solutions which suggested me to store the data appsettings.json, but since the data I want to store in the global variable is not static, I cannot use that setup. I need to set different data during runtime. How can I do that? Please help me.
IOptions<T>doesn't require anything inappsettings.json. Instead you can populate constants withservices.Configure<Type>(o => { o.Prop = "value"; });. Which would make it easier to change to json config later.