DEV Community

Cover image for Implicit Configuration in .NET
Guillaume Faas for Vonage

Posted on • Originally published at developer.vonage.com

3

Implicit Configuration in .NET

Hello friends,

In our last post, we demonstrated the process of registering Vonage clients within the .NET IoC container. This was a valuable step in simplifying interactions with our SDK.

Now, let's take a moment to ponder: What if we were to take this a step further?

Where Did We Leave Off?

Just a refresher: here's how we used to register those clients:

// Initialize credentials
Credentials credentials = ...
// Register our clients with a 'Transient' lifetime...
builder.Services.AddVonageClientTransient(credentials);
// Or a 'Scoped' lifetime
builder.Services.AddVonageClientScoped(credentials);
Enter fullscreen mode Exit fullscreen mode

You had to initialize a Credentials instance, typically from an ApiKey/ApiSecret pair or an ApplicationId/PrivateKey pair.
These values often came from your configuration file or were plucked from our Configuration instance.

You see where I'm going, don't you?

Implicit Configuration Loading

No more fussing about that Credentials instance anymore.
We've taken it further and tweaked the method to accept an IConfiguration instance immediately.

// Register our clients with a 'Transient' lifetime...
builder.Services.AddVonageClientTransient(builder.Configuration);
// Or a 'Scoped' lifetime
builder.Services.AddVonageClientScoped(builder.Configuration);
Enter fullscreen mode Exit fullscreen mode

Now, we handle all the heavy lifting as we'll grab all the necessary data straight from your configuration file.

Less manual work for you!

Extending With Environment-Specific Configuration

Until v6.9.0, we could only load configuration data from settings.json or appsettings.json.
It could be problematic if you wanted to use environment-specific values, for example, with a staging environment deployment.

You might have noticed that we are discussing loading data based on your local configuration.
What's the scoop there?

We're fetching all those crucial configuration values from sources you've loaded into your configuration builder.
For example, we can retrieve values from appsettings.{environment}.json, the default naming convention on a new .NET application.

Signing Off

Stay tuned for more features and quality-of-life improvements.

As always, we value your feedback!
So, feel free to hit up our GitHub repository to report issues, suggest improvements, or even contribute your pull requests. If you have questions, join us on the Vonage Developer Slack, and we will get back to you.

Happy coding, and see you soon!

Sentry mobile image

Improving mobile performance, from slow screens to app start time

Based on our experience working with thousands of mobile developer teams, we developed a mobile monitoring maturity curve.

Read more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay