.NET Development
Strongly Typed Configuration (Multiple Projects aka BLL or I am making a AzureGraph project
Gravatar is a globally recognized avatar based on your email address. Strongly Typed Configuration (Multiple Projects aka BLL or I am making a AzureGraph project
  Moojjoo
  All
  Feb 12, 2019 @ 08:33am

Rick Strahl, first and foremost I want to thank you for your blog and your openness to share your knowledge and I have always wanted to work in Hawaii.
Per your blog post - https://weblog.west-wind.com/posts/2016/May/23/Strongly-Typed-Configuration-Settings-in-ASPNET-Core

I have a project which does not require a startup however, it does have an appsettings.json that I add because you need configuration data.

Following your article, where do you propose putting the following code -

Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
        
    Configuration = builder.Build();
}

Also since this is not really an MVC application but rather a class library would I need to add services.AddMvc();

Mahalo

Gravatar is a globally recognized avatar based on your email address. re: Strongly Typed Configuration (Multiple Projects aka BLL or I am making a AzureGraph project
  Rick Strahl
  Moojjoo
  Feb 12, 2019 @ 12:19pm

If you're not using startup none of that works because it gets added to the dependency injection system. I think you can build the configuration provider independently but you just get the raw Configuration object, not the strongly typed functionality.

+++ Rick ---

© 1996-2024