0 1.2K en

Top 50+ NuGet Packages For .NET Engineer

Categories: 💻 Programming

In this article, we have collected the best Nuget packages for .NET development, which will be useful for you in your daily development activities

Mapping

Mapping

For domain encapsulation, we often use DTOs for our objects and mapping all the proprietary entities manually is not a good idea, some libraries do it for you, let's look at the most popular ones:

Riok.Mapperly

The runtime overhead is minimal since Mapperly creates the mapping code at build time. Consequently, it is a fairly performant lib.

  • Mapperly does not use reflection
  • Mapperly is safe for trimming and AoT
  • Mapperly runs at build time
  • Mapperly has no runtime dependencies
  • Generated mappings are fast with minimal memory usage
  • Generated mapping code is readable and debuggable
  • There is no need to write and maintain boilerplate manually
  • Mapperly is pluggable: you can always implement mappings for certain types manually, which Mapperly will pick up

An example of how it works can be seen in their documentation.

Mapster

  • Easy to use, high speed, and low memory consumption.
  • To use Mapster, we don't need to create any pre-configuration. It works through extension methods, so mapping an entity to a new instance of another class is very easy.

AutoMapper 

The most popular library, but not the most performance-well for mapping

Logging

Logging

Below are the most popular .NET libraries for logging

Serilog

Allows to write structured log by default. Otherwise, it is not inferior to analogs.

An example of how the log works:

var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;

log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);

The result is something like 

:14:22 [Information] Processed { Latitude: 25, Longitude: 134 } in 034 ms.

You can write logs in:

  • Console
  • File
  • DB
  • GrayLog

and more

NLog

NLog offers a configuration system that allows detailed customization of logging. Optimized for high performance and low resource consumption.

log4net

log4net is a time-tested solution that is used in many projects. It supports configuration via configuration files as well as programmatically.

The development of log4net is not as active as some other logging libraries.

Microsoft.Extensions.Logging

Tightly integrated with .NET Core and ASP.NET Core for easy customization and use. Allows easy switching between different logging providers without changing the application code.

Less functionality compared to specialized libraries: As an abstraction, may not provide some of the advanced features available in libraries such as NLog or log4net.

RDBMS и ORM

RDBMS и ORM'ки

There are many different libs for working with implementation databases, of course, the most popular are ORM EF and Dapper. DbUp is quite a powerful database migration tool. 

Entity Framework Core

It is an ORM framework from Microsoft designed to work with databases in .NET applications. It allows developers to work with data through .NET objects, minimizing the need to write SQL/NoSQL queries. Entity Framework Core supports database migrations, lazy loading, and automatic tracking of changes to objects to simplify development.

Dapper

Dapper — легковесный ORM фреймворк, который предоставляет минимальную абстракцию над SQL. Он разработан командой StackOverflow и ориентирован на производительность и простоту. Dapper позволяет напрямую работать с SQL запросами, обеспечивая высокую скорость выполнения за счет отказа от сложных функций, таких как автоматическое отслеживание изменений или ленивая загрузка, доступных в более тяжеловесных ORM, таких, как EF.

DbUp

DbUp is a set of .NET libraries that help deploy changes to various databases such as SQL Server. It keeps track of which SQL migrations have already been run and runs the ones needed to update the database. It works like EF migration, but if you are using Dapper or no ORM at all, DbUp will be useful.

NoSQL

NoSQL

Here are the most popular NoSQL solutions and NuGet packages for them:

MongoDB Driver

Libs for working with MongoDB from .NET applications. Details can be found in the official documentation.

AWS DynamoDB

This package provides convenient access to DynamoDB, allowing you to efficiently work with data in this NoSQL database, including operations to create, read, update, and delete data, as well as support for various data models.

RavenDB Client

RavenDB Client is a library for interacting with RavenDB, a NoSQL database.

Azure Cosmos DB

A lib to work with CosmosDB from Azure

Marten

Marten is a .NET library that allows you to use PostgreSQL as a document-oriented database. It offers easy manipulation of JSON documents directly in PostgreSQL, providing features such as LINQ queries, full-text search, and document versioning. 

HTTP

HTTP

Quite often you have to communicate with external APIs, The following libraries will help you with that:

Polly

Polly is a library for .NET for handling retries, Circuit Breaker, and other fault tolerance strategies. It allows developers to easily customize policies for retries, timeouts, exception handling, and more, making applications more robust when external call errors or temporary failures occur.

RestSharp

RestSharp is a simple and flexible HTTP client for .NET that makes it easy to interact with RESTful APIs. It supports asynchronous calls and automatic deserialization of responses

Refit

Refit is a REST client library for .NET that turns your HTTP API into a live .NET interface. Instead of manually creating HttpClient calls, Refit allows you to define an interface with methods and annotations that match your API. This simplifies your code, making it more readable and concise.

HttpFactory

Validations

Валидации

No .NET project can do without server-side data validation, below we will look at popular libs for this purpose:

FluentValidation

FluentValidation is a library for .NET designed to create powerful validation rules using an easy-to-read, almost natural language. It allows developers to define validation rules in individual validator classes, for example:

using FluentValidation;

public class CustomerValidator: AbstractValidator<Customer> {
  public CustomerValidator() {
    RuleFor(x => x.Surname).NotEmpty();
    RuleFor(x => x.Forename).NotEmpty().WithMessage("Please specify a first name");
    RuleFor(x => x.Discount).NotEqual(0).When(x => x.HasDiscount);
    RuleFor(x => x.Address).Length(20, 250);
    RuleFor(x => x.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");
  }

  private bool BeAValidPostcode(string postcode) {
    // custom postcode validating logic goes here
  }
}

var customer = new Customer();
var validator = new CustomerValidator();

// Execute the validator
ValidationResult results = validator.Validate(customer);

// Inspect any validation failures.
bool success = results.IsValid;
List<ValidationFailure> failures = results.Errors;

DataAnnotations

DataAnnotations are attributes built into .NET that can be applied directly to classes or properties to specify validation rules, metadata, or other instructions used by frameworks such as Entity Framework and ASP.NET MVC. DataAnnotations provide an easy way to incorporate basic validation and metadata directly into your application's data models. Although they are less flexible than FluentValidation, DataAnnotations offers a quick and easy way to add validation without having to create separate validator classes.

Auth

Auth

⭐Microsoft.Identity

Microsoft.Identity includes libraries such as Microsoft. Identity .Client (MSAL) and Microsoft.AspNetCore.Identity, is designed for user management, authentication, and authorization in .NET applications. MSAL simplifies integration with Microsoft Identity Platform (including Azure AD and Microsoft accounts) by providing access to security tokens to call secure APIs. AspNetCore.Identity offers APIs for managing users, passwords, profiles, roles, etc. in web applications.

Сценарии использования Microsoft Identity platrorm
Сценарии использования Microsoft Identity platrorm

Also with .NET 8 gaining popularity is the approach with Identity Endpoints.

Identity Server / Duende Identity Server

Identity Server / Duende Identity Server

Identity Server (now known as Duende Identity Server after commercialization) is an OpenID Connect and OAuth 2.0 framework for ASP.NET Core that allows you to implement your own authentication and authorization server. This solution is widely used to create security and identity systems that support modern standards and provide API protection.

And many other libraries depending on your needs....

For more complex cases it is worth considering ready-made solutions such as:

Testing

Тестирование

NUnit

A popular framework for unit testing in .NET, supporting many features for creating complex test scenarios.

xUnit

Another modern framework for unit testing, designed with the new features of .NET in mind. It offers an improved testing model compared to NUnit and MSTest, including support for parallel test execution and a unique fixture system.

FluentAssertions

Provides a set of extension methods that improve code readability and simplify working with Assets.

FakeItEasy

A library for creating fakes (stubs and mocks) in .NET, allowing easy replacement of dependencies in the code under test. It offers a simple and intuitive API for customizing the behavior of fakes.

Bogus

A mock data generator library for .NET. It allows you to easily generate test data for unit tests, stubs, or demo applications, supporting a wide range of data types.

WireMock.Net

Provides the ability to simulate HTTP servers for testing interactions with web services. This is useful for testing client code without having to access real web services, making testing faster and more reliable.

Moq

A library for .NET that allows you to create mocks for interfaces and classes.

NSubstitute

A mocking and stubbing library with a simple API focused on usability and ease of use. It allows you to customize return values ​​and test method calls without having to write a lot of boilerplate code.

AutoFixture

A library that automates the setup of test data for unit tests by creating objects with pre-populated data automatically. This reduces the amount of manual coding required and simplifies the preparation of data for tests.

SpecFlow.NUnit

SpecFlow.NUnit Integrates the SpecFlow BDD (Behavior-Driven Development) framework with NUnit, allowing developers to define tests via natural language specifications.

Task Schedulers

Task Schedulers

Quartz.NET

Quartz.NET — full-featured task scheduler for .NET applications that allows developers to run tasks on a schedule. It supports simple and complex scheduling scenarios, including the ability to use CRON expressions. Quartz.NET can be used to add complex task schedulers to any .NET application.

Hangfire

Hangfire — a framework for background task execution in .NET applications that allows you to schedule and execute tasks asynchronously in the background. It offers a convenient dashboard for monitoring and managing background tasks, supports task persistence, and does not require a separate service for managing task queues.

FluentScheduler

FluentScheduler — is a task automation library for .NET that allows you to easily schedule tasks using the fluent API. It supports one-time and recurring tasks and provides the ability to organize tasks into groups for easy management.

NCrontab

A library that provides a parser and formatted for CRON expressions in .NET. While not a task scheduler in itself, it can be used in conjunction with other tools to extend the capabilities of task scheduling using the standard CRON format.

Messaging

Messaging

RabbitMQ.Client

Library for working with RabbitMQ

Kafka

Library for working with Kafka

Confluent.Kafka

Confluent.Kafka is a .NET client for Apache Kafka developed by Confluent. This library provides a performant and convenient API for publishing and consuming messages from Kafka. Confluent.Kafka is tightly integrated with Kafka and supports all of Kafka's core capabilities, including transactions, stream processing, and schema management via the Confluent Schema Registry.

MassTransit

is a lightweight library for .NET that makes it easy to work with message brokers such as RabbitMQ and Kafka. It provides a high-level API for asynchronous communication between application components via messages. MassTransit simplifies the implementation of complex messaging patterns and includes integration with message versioning systems, compensation transactions, and monitoring.

Caching

Кеширование

ZiggyCreatures.FusionCache

The powerful library supports both in-memory and distributed cache— my recommendation.

Microsoft.Extensions.Caching

Microsoft.Extensions.Caching includes two main cache implementations: MemoryCache and DistributedCache

Others

MediatR

The library implements Mediator pattern, which helps to reduce the direct dependency between program components, simplifying their testing and support.

Newtonsoft.Json

A popular library for working with JSON.

System.Text.Json

An alternative to Newtonsoft.Json for working with Microsoft's JSON.

GraphQL

Library for working with GraphQL.

 

In the comments, write what is missing and what else should be added.

Comments:

Please log in to be able add comments.