Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Issue/clarification around injecting IConfiguration #10744


User avatar
0
tusksoft created

v10.2.0 Angular .net5 abp v 6.2.0

I had a longer version of this typed up but my session was lost and along with it my original post, so here's the boiled down version.

A complete version of IConfiguration is not available to my class libraries without adding services.AddSingleton<IConfiguration>(configuration); to Startup.ConfigurServices. Without that line IConfiguration only has a single provider for environment variables. When I add the line I get a fully populated instance of IConfiguration. Prior to aspnetcore2 explicitly configuring IConfiguration for the container with aforementioned line was required, without it the injected instance would be null (such is my understanding, I never used netcore1.x versions). Starting with aspnetcore2 IConfiguration should be implicitly configured and services.AddSingleton<IConfiguration>(configuration); should not be necessary, but in A0 it seems to be.

I can find no documentation for A0 nor ABP that details this. Is this by design or a bug? If the former, can you elaborate on the reasoning and intention?

Here's what the IConfiguration instance looks like without explicitly adding it to the container:

Here's what it looks like with the explicit configuration:


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    AspNet Zero uses IAppConfigurationAccessor to support accessing/mocking configuration in Test project and other project types. You can inject IAppConfigurationAccessor and use it.

  • User Avatar
    0
    tusksoft created

    So is A0 somehow removing the implicit configuration for IConfiguration? What is the reasoning behind this?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @tusksoft

    I got the problem now. Normally it shouldn't be like this. I will check it and get back to you.