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

376
Views
In ASP.NET Core, how do I use a service that is setup in ConfigureServices() in Configure()?

I have a service I wrote that helps with configuration. The service is set up in the Startup class's ConfigureServices method as:

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddScoped<IMyService, MyService>();

    ...
}

I need to then get an instance of IMyService in the Startup class's Configure method. How do I do that?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since you've already added your service with AddScoped, all you need to do is add another parameter to the Configure method with the correct type and the dependency injection system will take care of it for you:

public void Configure(IApplicationBuilder app, 
    IHostingEnvironment env, 
    ILoggerFactory loggerFactory, 
    IMyService myService)
{
    //Snip
}
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!