I have a server-side Blazor web app that I want to be able to add Blazor web component libraries to for "sub apps". I am able to do this by modifying App.Razor and adding AdditionalAssemblies for each component. I have a ServiceCollection extension as part of the component for injecting various services and DbContexts needed by each component. This is then called in the Services section of main app's program.cs file.
So far so good, but now I would like to get the IConfiguration piece somehow passed into the Component so that I can use it throughout the component.
I use the pattern of reading the Appsettings.json file into a set of classes representing the various configuration sections.
Any suggestions on how to do that?
My Component's service extension:
public static class ConfigureServicesExtension
{
public static void AddMyComponentServices(this IServiceCollection services)
{
services.TryAddScoped<MyComponentService>();
services.AddDbContext<MyDbContext>(options =>
options.UseSqlServer("name=ConnectionStrings:MyDbContext"));
}
}