.net maui full course

.NET 8

 Want to unlock real SQL performance? You'll need to understand how an Index works.

Did you ever use a filtered index in a SQL database? A filtered index only includes records that meet the specified criteria.

However, if almost all your records match the filter, this index has low selectivity. I thought this might be interesting to share, as many developers shy away from SQL.
 
If you want to see how you can use this with EF Core soft deletes, here's an in-depth article: https://lnkd.in/eFBDcvKX

 


 With .NET 8, we can also start these background services concurrently.

 


How do your services find and communicate with each other reliably?

Hardcoding IP addresses is a recipe for fragility.

Enter service discovery.

Service discovery allows you to refer to external services using logical names. It provides a centralized location for services to register themselves (IP + port). Clients then query the service registry to find the service's physical address. This is a common pattern in large-scale distributed systems.

Here's what the service discovery flow looks like:

1. The service will register itself with the service registry

2. The client must query the service registry to get the physical address

3. The client sends the request to the service using the resolved physical address

Here's how you can implement Service Discovery in .NET using Consul: https://lnkd.in/e8QrVRrv

Are you looking for a lightweight solution?

There's a .NET library that implements a light version of service discovery. Instead of a service registry, you provide the physical addresses through app settings.



Clean Code



.NET 8 added a resilience library that uses Polly.

With one line of code, you can configure a Circuit Breaker, Retries, and Timeouts.

Here's how this improves your application's resilience: https://lnkd.in/epDq8_Rn

  𝐖𝐡𝐲 𝐈 𝐝𝐨𝐧'𝐭 𝐮𝐬𝐞 𝐀𝐮𝐭𝐨𝐌𝐚𝐩𝐩𝐞𝐫 𝐢𝐧 𝐦𝐲 𝐩𝐫𝐨𝐣𝐞𝐜𝐭𝐬 𝐚𝐧𝐲𝐦𝐨𝐫𝐞


AutoMapper library automates the process of object mapping and reduces the boilerplate code. On paper, this library should make you more productive and minimize the risk of errors, but the reality is the opposite.

𝐃𝐞𝐬𝐩𝐢𝐭𝐞 𝐭𝐡𝐞 𝐚𝐝𝐯𝐚𝐧𝐭𝐚𝐠𝐞𝐬, 𝐀𝐮𝐭𝐨𝐌𝐚𝐩𝐩𝐞𝐫 𝐚𝐥𝐬𝐨 𝐜𝐨𝐦𝐞 𝐰𝐢𝐭𝐡 𝐬𝐞𝐯𝐞𝐫𝐚𝐥 𝐩𝐨𝐭𝐞𝐧𝐭𝐢𝐚𝐥 𝐝𝐫𝐚𝐰𝐛𝐚𝐜𝐤𝐬:

- Performance Overhead - mapping libraries often use reflection to inspect and map object properties at runtime.

- Complex configurations - while mapping libraries aim to simplify the mapping process, they can sometimes lead to complex configurations, especially for advanced scenarios. Configuring custom mappings, value resolvers, and type converters can become cumbersome and error-prone.

- Debugging Challenges - when using mapping libraries, debugging mapping issues can be challenging. Errors might appear only at runtime, making it harder to trace and fix problems.

- Error prone - if you ever used mapping libraries in real applications, I am certain that you have run into runtime errors, only because you forgot to update the mapping profile after adding a new property to the mapping object.

As for me, the biggest drawback is not related to performance (because performance is situational) but the maintability and debugging issues.

In a real big project AutoMapper caused more troubles than it solved:

- Developers were able to forget to update the mapping profile after adding new properties to one of the models. Without a good test coverage you will catch a bug only in the runtime
- Developers spent a lot of time trying to debug the mapping code (time waste)
- Developers spent a lot of time searching for a mapping profile in a big solution.

Having these drawbacks in place, I totally moved to manual mapping with using the required keyword in C#.

𝐓𝐡𝐢𝐬 𝐠𝐢𝐯𝐞𝐬 𝐦𝐞 𝐭𝐡𝐞 𝐟𝐨𝐥𝐥𝐨𝐰𝐢𝐧𝐠 𝐚𝐝𝐯𝐚𝐧𝐭𝐚𝐠𝐞𝐬:

- Easy Navigation. You don't need to search for mapping classes in the entire solution to understand how the libraries do the mapping magic.

- You have code safety. If you forget to update the mapping method - a compiler error is raised.

- You have entire control over the mapping process, you don't need to spend time learning how to do the fancy mapping stuff in the libraries.

- Better performance

- Straightforward Debugging. This is really hard or almost impossible to debug an AutoMapper profile. Forget about this problem and have the stress-less debugging.



Comments