Milan Jovanoviฤ‡ Profile picture
Oct 6, 2023 โ€ข 1 tweets โ€ข 1 min read โ€ข Read on X
How can you ๐˜ƒ๐—ฎ๐—น๐—ถ๐—ฑ๐—ฎ๐˜๐—ฒ JSON ๐—ฐ๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฒ๐˜€ in .NET?

I use the Options pattern to create strongly typed configuration values.

The values can come from:

- JSON files
- Application secrets
- Environment variables
- Azure App configuration

However, setting up configuration values is error-prone.

Here are just a few things that can go wrong:

- Passing an incorrect section name to IConfiguration.GetSection
- Forgetting to add the settings values in appsettings.json
- Typo in a property name in the class or the configuration
- Data type mismatch resulting in incompatible values
- Unbindale properties without a setter

The application will behave differently at runtime depending on which one of these mistakes is made.

The best-case scenario is that the incorrect application settings cause a runtime exception.

You realize you have a problem and fix it.

The worst-case scenario is that the application silently fails.
The problem may go undetected for some time.

Data annotations are a simple way to introduce validation to the settings class.

However, you can also integrate FluentValidation using the IValidateOptions interface.

If you liked this, consider joining The .NET Weekly - my newsletter with 29,000+ engineers.

Join us here โ†’

Are you using the Options pattern?
Image

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Milan Jovanoviฤ‡

Milan Jovanoviฤ‡ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mjovanovictech

Aug 10, 2023
Thinking about separate read/write databases?

Here's what you should know first.

Using separate read and write databases offers a range of benefits:
- Better performance
- Increased scalability
- Fault tolerance

Let's break them down. Image
๐—•๐—ฒ๐˜๐˜๐—ฒ๐—ฟ ๐—ฝ๐—ฒ๐—ฟ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐—ป๐—ฐ๐—ฒ

By separating reads from writes, you can tune each database for its specific purpose.
๐—œ๐—ป๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜€๐—ฒ๐—ฑ ๐˜€๐—ฐ๐—ฎ๐—น๐—ฎ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜†

You can scale each database independently when using separate read and write databases. This is particularly useful when your application's queries lean heavily to one side.
Read 8 tweets
Aug 9, 2023
What is the RIGHT way to use HttpClient in .NET?

HttpClient is an excellent abstraction and incredibly easy to work with.

Unfortunately, it's also easy to misuse, leading to problems like port exhaustion.

You need to know how NOT to use it. Image
If you think IHttpClientFactory will solve all your problems, you're only partly right.

Should you use named clients or typed clients?

Microsoft was kind enough to provide us with a set of best practices and recommended use for HttpClient.
- Use a static or singleton HttpClient instance with a PooledConnectionLifetime configured since this solves both port exhaustion and tracking DNS changes
Read 6 tweets
Jul 25, 2023
What is a webhook?

Imagine this:

You have a website or an application, and you want it to automatically do things without you having to trigger them manually.

That's where webhooks come in! Image
Webhooks are like little messengers that allow one system to send a message or data to another system in real-time whenever a specific event happens.

It's like getting a notification on your phone when someone comments on your social media post or when you receive an email.
Webhooks work similarly but for systems and applications.

A webhook is a way for one system to send a message or data to another system in real-time whenever something important happens.
Read 9 tweets
Jul 24, 2023
You don't need to start with Microservices.

Even if you're confident your application will be big enough to justify Microservices.

And here's why. ๐Ÿ‘‡

Microservices come with a premium. Image
The Microservices premium:
- Team coordination
- Dealing with failure
- Eventual consistency
- Automating deployments
- Managing multiple services

And many other factors.
You probably don't need this complexity at the start of a new project.

Ask yourself:
- Is it valuable to your users?

The experience of your team plays a significant role.
Read 7 tweets
Jul 17, 2023
What are the SOLID principles? ๐Ÿค”

As a .NET developer, I'm always looking for ways to improve the quality and maintainability of my code.

I want to share my experiences using the SOLID principles and how they've helped me create better code. Image
First, let's define what we mean by SOLID.

The acronym ๐—ฆ๐—ข๐—Ÿ๐—œ๐—— stands for:
- Single responsibility principle
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle

Let's break them down. ๐Ÿ”ฌ
1. ๐—ฆ๐—ถ๐—ป๐—ด๐—น๐—ฒ ๐—ฅ๐—ฒ๐˜€๐—ฝ๐—ผ๐—ป๐˜€๐—ถ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜† ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐—ฆ๐—ฅ๐—ฃ)

A class should have only one reason to change. In other words, a class should have a single, well-defined responsibility. That class should entirely encapsulate responsibility.
Read 13 tweets
Jul 12, 2023
I've been using Clean Architecture for 5 years and counting.

Here's why I think it's amazing. ๐Ÿ‘‡

Clean architecture isn't revolutionary.

But it is opinionated about how to structure your code.

It's just another form of layered architecture.
The core concept you need to grasp is the Domain.

Another way to think about Clean architecture is that it's a Domain-centric architecture.

The Domain is at the center of the architecture, and it's treated as the most essential part.

The other components support the Domain.
What are some common Domain-centric architectures?
- Hexagonal architecture
- Clean architecture
- Onion architecture

They all revolve around the same idea.
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(