Answers for "appsettings in console application c#"

C#
0

appsettings in console application c#

public Startup()
{
    var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

        configuration = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                        .AddJsonFile($"appsettings.{environment}.json", optional: true)
                        .AddEnvironmentVariables()
                        .Build();
}
Posted by: Guest on May-22-2020
0

appsettings in console application c#

using System;
using Microsoft.Extensions.Configuration;

namespace DiConsoleApp
{
    public class SomeService : ISomeService
    {
        IConfiguration configuration;

        public SomeService(IConfiguration configuration)
        {
            this.configuration = configuration;    
        }

        public void DoProcess()
        {
            var value = configuration["SomeKey"];
            Console.WriteLine("Value from the Config is: " + value);
        }
    }
}
Posted by: Guest on May-22-2020
0

appsettings in console application c#

<ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3" />
</ItemGroup>
Posted by: Guest on May-22-2020
-1

appsettings in console application c#

{
    "SomeKey": "This is from Config!"
}
Posted by: Guest on May-22-2020

Code answers related to "appsettings in console application c#"

C# Answers by Framework

Browse Popular Code Answers by Language