Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Getting settings from appsettings.json to afterStarted(options) in Blazor | Blazor Server

i want to set variable (someFlag = false/true) in JS so i can disable/enable javascript function.

I would like to do it with afterStarted(options) [described in link below].

https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#javascript-initializers

The question is:

Is there any way to get the data from appsettings.json to function afterStarted(...). Either through options parameter or something else, doesn't matter.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe inject IConfiguration into the blazor page?

@inject IConfiguration _configuration


protected override afterStarted(){
    var somevariable = _configuration["othervariable"];
}

Failing that, I create an object like ApplicationState with an interface, make that a scoped service in Program.cs, define the object's properties, then inject that interface into your blazor page:

Program.cs

builder.Services.AddScoped<IApplicationState, ApplicationState>();
var applicationState = app.Services.GetRequiredService<IApplicationState>();
applicationState.someVar = builder.Configuration["SomeVar"];

blazor

@inject IApplicationState _applicationState

protected override afterStarted(){
    var somevariable = _applicationState.someVar;
}

Hope this helps

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!