.NET 5 tips and tricks for coding
.NET 5 implements some good features that help us to write better code. One of the most useful for having safer code is dependency injection (DI), which was already discussed in Chapter 11, Design Patterns and .NET 5 Implementation. There are some good reasons for considering this. The first one is that you will not need to worry about disposing the injected objects since you are not going to be the creator of them.
Besides, DI enables you to inject ILogger
, a useful tool for debugging exceptions that will need to be managed by try-catch
statements in your code. Furthermore, programming in C# with .NET 5 must follow the common good practices of any programming language. The following list shows some of these:
- Classes, methods, and variables should have understandable names: The name should explain everything that the reader needs to know. There should be no need for an explanatory comment unless these declarations are public. ...