I have seen a lot of examples doing this and am wondering if they are advised.
Scenario
Lets assume I have a database that has some details about how to register a service with DI, for sake of simplicity lets assume my service requires a URL to work along with other data.
So in ConfigureServices()
I wish to access the DBContext
to fill this data. There are many examples suggesting you can do it by calling services.BuildServiceProvider();
and then you can access the DBContext
. Although this works its not suggested to do it this way.
How can I access my DBContext
within the ConfigureServices method in a way that I can read settings to configure additional services?