global variable startup file .net core api
public class MDUOptions
{
public string CompanyCode { get; set; }
}
global variable startup file .net core api
public class MDUOptions
{
public string CompanyCode { get; set; }
}
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;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us