Answers for "global variable startup file .net core api"

0

global variable startup file .net core api

public class MDUOptions
{
    public string CompanyCode { get; set; }
}
Posted by: Guest on June-25-2021
0

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;
    }
}
Posted by: Guest on June-25-2021

Code answers related to "global variable startup file .net core api"

Browse Popular Code Answers by Language