Giter VIP home page Giter VIP logo

Comments (3)

rogusdev avatar rogusdev commented on August 27, 2024

Hey, thanks for asking for help. :) Tbh tho, I'm not sure what you are trying to do here. It looks like you copy-pasted a couple examples directly from the readme (comments included), but did not read what they do, as the combination you put together does not seem likely to give you the desired result.

Of particular note, the NoEnvVars() config option is for loading a .env without modifying env vars, which sounds like is the opposite of what you want.

I recommend you read the readme for the options you have chosen and then explain your intent with them, if my comment above does not already resolve your ask.

from dotnet-env.

Philipp-Binder avatar Philipp-Binder commented on August 27, 2024

Not sure which type of project you use, but anyway you shouldn't add IConfiguration manually as Singleton.

As an example from net7.0-Project just add the following in your Program.cs:

builder.Host.ConfigureAppConfiguration(configurationBuilder => configurationBuilder.AddDotNetEnv(...));

Adding the IConfiguration manually will have no effect because there is a default IConfiguration-Service provided by the baseFramework, which will be used instead of the manually added one. (the default one gets added first and first one "wins")

Your second sample seems like you want to have a separate configuration instead of "extending" the default one.
In general I would recommend to use a separate section in the default configuration instead of creating your own configuration.

If you still want to have your own confuguration you may add an additional interface, something like

interface IVeneliteConfiguration : IConfiguration { }

and add the singleton manually but for this new interface; but as I said, I would not reccomend that.

Instead, add VeneliteConfiguration__ in front of your Env-Vars, add it to the default config (as I described at first), and to bind it navigate to the section first and bin it then:

var appSettings = new VeneliteConfiguration();
Configuration.GetSection("VeneliteConfiguration").Bind(appSettings);

You can replace that with a oneliner too (this will create the objtect and bind it exactly as above):

var appSettings = Configuration.GetSection("VeneliteConfiguration").Get<VeneliteConfiguration>();

This way you are able to split your config in multiple parts too, no need for a single huge config-object holding everything.

from dotnet-env.

rogusdev avatar rogusdev commented on August 27, 2024

Closing due to lack of clarification.

from dotnet-env.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.