C# offers libraries that are used by millions of projects. Libraries make your life easier because you won’t reinvent the wheel again. The main purpose of a developer is to solve a particular problem, not to find solutions for many problems.
Dapper is built by StackExchange, which also built StackOverflow, and it’s an alternative for Entity Framework. This ORM is faster than Entity Framework, but you have to write your own queries. So, if you like to write SQL and you hate the queries that Entity Framework generates for you, then Dapper is the best choice.
When you must map one object to another, then AutoMapper is the first choice. Whenever you need to copy the properties of an object to a DTO, then AutoMapper can do it for you. Automapper has some great features:
- Mapper Profiles
- Dependency Injection
- Custom Mapping Methods
Serilog is the most popular library for logging in .NET. You can configure Serilog to display your logs in the console, files, database, etc… You can set different types of importance for each log like verbose, debug, info, warning, error, and fatal.
Swagger is a way to create documentation automatically for your RESTful APIs. The interface is built using the help of OpenAPI, which gives the option to understand the services, without the source code.
MiniProfiler can help you to identify easily how fast a page is loading and what parts of your code need more time to execute. You can see how many SQL queries are generated and the code for them.
MiniProfiler, like Dapper, is built by StackExchange, so expect something which is well built. Regardless of the project, this is the first library that I include.
Hangfire is your first choice when you need to run tasks in the background. It keeps in the database the tasks that should run, so your jobs will not be lost if something bad happens. You have evidence of the tasks that didn’t end successfully.
There are different types of jobs: delayed, fire-and-forget, recurring, or continuations. In the paid version you also have the possibility to run batches.
Sometimes you call an external service that can give you failures without a logical reason for you, for example, a service that is heavily called, then you need something to retry. Polly is the greatest library to execute again failure calls.
This is a resilience library that has multiple policies available:
- Retry: until it’s successfully or exceeds the limit number of calls
- Circuit breaker for some time
- Set a timeout period or how much a task can be retried
- Return the result from the cache if the call is similar
- Bulkhead isolation
For REST API calls, RestSharp is a perfect choice.
You can also use it to send simple HTTP requests. RestSharp is the first choice when you need an HTTP client in C#.
This library has over 70 million downloads.
Whenever you need to read or write a CSV File, you can use CsvHelper. It’s easy to use, and you can use it using classes or dynamics.
CSV Helper is the fastest C# library for manipulating separated value files.
As the name says, this library can build validations and rules for an object, using fluent syntax. You can validate business objects using the built-in validators, or you can do your own business rules.
This is an HTML parser for C#, that can download web pages and load them in memory. You can perform queries using XPath or use the built-in methods that the library offers.