Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Dependency Injection IApplicationEnvironment Error

$
0
0

The whole day I am trying to get this working.

I am doing a dependency injection via this code:

public Startup(IApplicationEnviroment appEnv)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();

    Configuration = builder.Build();
}

Everytime when I am executing this code I am getting the following error:

enter image description here

I am really annoyed of that because I can't get it working and I have no clue about it. I am relatively new to Asp.Net and C# but this is how the tutorial said me to do. Does everyone know what my problem about the code is?


Maybe this helps.

#if DEBUG
        services.AddScoped<IMailService, DebugMailService>();
#else
        services.AddScoped<IMailService, RealMailService>();
#endif

My Interface:

public interface IMailService
{
    bool SendMail(string to, string from, string subject, string body);
}

My DebugMailService

public class DebugMailService : IMailService
{
    public bool SendMail(string to, string from, string subject, string body)
    {
        Debug.WriteLine($"Sending mail: To: {to}, Subject: {subject}");
        return true;
    }
}

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>