I want to use the same code and hopefully configuration to set up DI for both ASP.NET core and .net core command-line tools.
I understand how to use Startup.cs to configure services for ASP.NET core. I understand how to build a ServiceCollection
in a command-line tool, though other than accessing it explicitly, I am not exactly sure how to use it, and I think my CLT has to manage the service collection itself (unlike ASP.NET that provides a service collection and constructor injection).
Can my web and CLT projects use the same extension method to register my services? Startup.ConfigureServices
would pass the ServiceCollection
and Configuration that it receives to my extension method. The CLT I can pass the ServiceCollection
that the CLT manages, but can it get the same type of Configuration from an appsettings.json
file?