Answers for "global variable startup file .api"

0

global variable startup file .api

global variable startup file .net core api
Posted by: Guest on June-25-2021
0

global variable startup file .api

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

Browse Popular Code Answers by Language