Comments (3)
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.
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.
Closing due to lack of clarification.
from dotnet-env.
Related Issues (20)
- BUG FakeEnvVars is not threadsafe HOT 3
- Is there support for hierarchical settings? HOT 2
- how to use .env file in production? HOT 1
- Fails to parse when environment file has dash (-) HOT 9
- Not Able to read env variables for project type .NET Framework 4.7.2 HOT 2
- Make change to README file HOT 7
- Creating a IConfigurationBuilder method extension for environment variables HOT 5
- Env file not loading HOT 3
- Vulnerability issue v2.3.0 HOT 1
- Environment variables for .NET Framework 4.7.2 set on a run basis rather than on a project root folder basis HOT 7
- Suggestion: Defaults Are Unexpected
- Add readme to nuget package HOT 1
- 2.4.0 Doesn't Work - Fails to Load .env HOT 19
- Encryption HOT 1
- Transitive Dependency System.Net.Http 4.3.0 contains vulnerabilities according to Checkmarx HOT 4
- Denial of Service (DoS) - v2.5.0 HOT 1
- Interpolation stops working with `SetEnvVars == false` HOT 3
- Support default values for variables HOT 13
- Migrate from Sprache to Superpower
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnet-env.