This repository contains a curated list of modern, open-source .NET libraries which are of general use, particularly in the context of an ASP.NET Core web application.
Each section lists a recommended library or libraries, optionally followed by one or more good alternatives.
- Background Jobs
- Caching
- Compile-time Dependency Injection
- Console Applications
- Email Templating
- Encryption
- ETL
- Event/Message Bus
- File Storage
- GUI Applications
- Logging
- Markdown to HTML
- Mediator Pattern
- ORM and Database Access
- PDF Generation
- Reverse Proxy/API Gateway
- Testing
- Workflows
Hangfire is a mature and powerful background job manager which requires minimal setup. Using Redis rather than a SQL database as the backing storage improves throughput. The official Redis support requires a paid 'pro' license, but the open-source StackExchange.Hangfire.Redis repo provides a free alternative.
Since ASP.NET Core applications run in a persistent process, non-distributed caching can be implemented without external infrastructure dependencies. Bitfaster.Caching offers a good set of features and high performance. CacheTower offers a multi-layered caching system, which could be useful if caching large amounts of expensive queries which do not fit easily in memory.
For a distributed Redis cache, one can use StackExchange.Redis together with the Microsoft.Extensions.Caching.StackExchangeRedis IDistributedCache
implementation (see here).
- StackExchange.Redis (GitHub)
ASP.NET Core has built-in dependency injection feature which is sufficient for most use-cases. However, the following source generator libraries promise increased performance.
Sadly, owing to the design of ASP.NET Core, it is not yet possible to fully integrate compile-time libraries and thereby fully replace the built-in runtime dependency injection mechanics:
- Jab (GitHub)
- StrongInject (StrongInject)
- ConsoleAppFramework (GitHub)
System.CommandLine is sufficient for very simple scenarios.
- System.CommandLine (GitHub)
Scriban is a high-performance templating engine which can used not only for email templating, but many other purposes besides. Fluid claims to be even faster than Scriban.
- Encrypt We Must (GitHub)
- Transformalize (GitHub)
CAP supports the transactional outbox pattern, which can be helpful for reliability. MessagePipe is by Cysharp, who is famous for high-performance libraries. Rebus has been around for a long time and is battle-tested and well-documented.
FluentStorage is an abstraction for blob storage across multiple cloud providers (and local files). It is well-documented.
- FluentStorage (GitHub)
- ZLogger (GitHub)
- gelf-extensions-logging (GitHub)
- Markdig (GitHub)
- Mediator (source generator) (GitHub)
- MediatR (GitHub)
Entity Framework is an incredibly powerful ORM which provides advanced, strongly-typed querying capabilities, good performance - particularly since a host of improvements were made in EF Core 6 - and inbuilt support for the unit of work pattern. EFCore.BulkExtensions can be used to improve performance when dealing with bulk CUD operations, the impact of which becomes noticeable when dealing with operations on 100s or 1000s of entities. If a second-level cache is required, EF Core Second Level Cache Interceptor can be used.
In advanced scenarios, when more than one database transaction may be required per web request, the DbContextScope library is useful. This allows for more fine-grained control over the lifetime of the DbContext than simply injecting the DbContext as a scoped dependency. For more information, see Mehdi El Gueddari's 2014 article here.
To allow for primary keys that can be generated in application code and can be more efficiently sorted than standard GUIDs (particularly in databases which do not support non-clustered primary keys), consider ULIDs or COMB GUIDs.
- Entity Framework Core (GitHub)
- EFCore.BulkExtensions (Homepage | GitHub) (NB: PAID license)
- EF Core Second Level Cache Interceptor (GitHub)
- DbContextScopeEFCore (GitHub)
- Cysharp/Ulid (GitHub)
- RT.Comb (GitHub)
The following are lighter-weight alternatives which do not offer the full functionality of Entity Framework Core:
Marten is a powerful library which allows PostgreSQL to be used as a hybrid/NoSQL database:
There aren't many PDF generators that don't rely on headless browser rendering of HTML (regardless of programming language; cf. e.g. mpdf in PHP, although the source code looks hard-to-maintain). However, the non-browser approach yields much better performance. QuestPDF is one such library on .NET.
A good combination of libraries for implementing tests is xUnit as the test framework, NSubstitute for test doubles, Bogus for the generation of fake data and FluentAssertions for assertions.