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

175
Views
C# - .NET 6 - Aplicación de consola con host genérico frente a sin

Estoy usando las nuevas declaraciones de nivel superior en .NET 6 para crear una aplicación de consola simple, pero no entiendo las ventajas/desventajas de usar el "Host genérico". ¿Puedes explicar?

Mi código con Generic Host:

 using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; Console.WriteLine("Hello, World!"); using var host = Host.CreateDefaultBuilder(args) .ConfigureServices((_, services) => { services.AddTransient<ITestInterface, TestClass>(); }) .Build(); Test(); Console.ReadKey(); void Test() { var testClass = host.Services.GetRequiredService<ITestInterface>(); testClass.TestMethod(); }

versus

 using Microsoft.Extensions.DependencyInjection; Console.WriteLine("Hello, World!"); var services = new ServiceCollection(); services.AddTransient<ITestInterface, TestClass>(); var servicesProvider = services.BuildServiceProvider(); Test(); Console.ReadKey(); void Test() { var testClass = servicesProvider.GetRequiredService<ITestInterface>(); testClass.TestMethod(); }
over 4 years ago · Santiago Trujillo
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!