declare global variable in startup file in .net core api
1.MDUOptions:
public class MDUOptions
{
public string CompanyCode { get; set; }
}
2.Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
Action<MDUOptions> mduOptions = (opt =>
{
opt.CompanyCode = "aaaa";
});
services.Configure(mduOptions);
services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<MDUOptions>>().Value);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
3.ValuesController:
public class ValuesController : ControllerBase
{
private static string _mduDb;
public ValuesController(MDUOptions options)
{
_mduDb = options.CompanyCode;
}
}