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

225
Views
¿Cómo funciona el delegado Func cuando requiere una interfaz como parámetro?

Específicamente, estoy viendo esta línea de código de Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.cs:

 public static IServiceCollection AddScoped<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory) where TService : class;

Un ejemplo usando este método sería:

 services.AddScoped<ICustomService>(sp => new CustomService( sp.GetRequiredService<IAnotherCustomService>(), "Param1", "Param2"));

Entiendo cómo funcionan el delegado de Func y las expresiones lambda, pero no entiendo cómo se inicializa IServiceProvider detrás de escena.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

IServiceProvider no se inicializa en segundo plano en este momento. El marco simplemente captura el delegado pasado y lo guarda para un momento posterior, cuando tiene una instancia de IServiceProvider y necesita generar un ICustomService .

No hay nada específico para las interfaces que sucede aquí. El mismo principio se aplicaría con cualquier tipo de argumento para un delegado.

 // This captures the delegate in a variable Func<int, string> f = i => i.ToString(); // This invokes the delegate with an instance of an `int` f(1); f(2);
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!