Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If I understand the problem, just move all your DI registrations to a shared extension method:

  public static ConfigurationExtensions{
      public static AddMyApp(this IServiceCollection services){
           services.AddScoped<IFooService,FooService>();
      }
  }

  //In console app:
  var consoleBuilder = Host.CreateApplicationBuilder(args);
  consoleBuilder.Services.AddMyApp();
  ...
  //pseudocode - in real world you'd put this in another class or method called by the commandline code:
  if(webHostCommandLineSwitch){
      var webBuilder = WebApplication.CreateBuilder(args);
      webBuilder.Services.AddMyApp();
     ...
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: