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

152
Views
Binding options inside other options services.Configure<>()

Imagine I have the following settings in appsettings.json :

  {
  "OtherSettings" : {
    "id" : 3
  },
  
  "Needed" : {
    "Database" : {
      "ConnectionString" : "abc123"
    },

    "Interval" : {
      "is_active" = true,
      "in_seconds" = "15" 
    }
  } 
}

For the Database section I've got an class which is DatabaseSettings with property ConnectionString.

And for the Interval section I've got the class IntervalSettings.

If I would like to bind all those settings inside Needed to an class NeededSettings, what property do I need and how would I bind the options for the Database class with Dependency Injection ? Currently I am doing this with:

services.Configure<DatabaseSettings>Configuration.GetSection("Needed:Database"));
services.Configure<IntervalSettings>(Configuration.GetSection("Needed:Interval"));

So I am doing this with 2 lines, but I want to do it in 1 line and bind all the settings to the new class NeededSettings

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simply remove these two lines and add:

services.Configure<NeededSettings>(Configuration.GetSection("Needed"));

and use NeededSettings in all places you used DatabaseSettings and IntervalSetttings.

Edit:

public class NeededSettings{
    public DatabaseSettings Database {get;set;}
    public IntervalSettings Interval {get;set;}
}

over 4 years ago · Santiago Trujillo 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!