Know The Libraries
While the .NET Framework Class Library (FCL) provides a wide variety of classes for most scenarios, its third party library ecosystem has blossomed in recent years to address some insufficiencies and many of them are worth knowing. Here, we will cover some of the most useful, popular, and more importantly, open source thus consequently free, third party libraries to help you select the best library for your needs.
As the name suggests Json.NET is a library for working with JSON, providing methods for serializing and deserializing between JSON and .NET objects. It is highly customizable, allowing you to specify how the JSON should be formatted, how to handle dates, how the property names should be capitalized, and so on. Json.NET is available as Portable Class Library, making is usable for Xamarin and Windows Phone projects as well.
Created by StackExchange, Dapper is a lightweight objectmapper, compatible with any database that has an ADO.NET provider. Simply, it executes a query and maps results to your classes; it does not generate database queries or model classes for you. What makes Dapper stand out from other, similar libraries? Speed. Dapper is a lot faster compared to the Entity Framework and only a little bit slower than raw ADO.NET.
Detailed logging not only allows you to monitor application performance but it’s also key to diagnosing issues in production. NLog comes with dozens of layout renderers that declaratively add contextual information to every log message. NLog is extensible too, letting you create a custom log target or a custom layout renderer. Configuration options allow you to log to a file system, directly to a database, track an event log, plus logging via email.
Topshelf makes writing a Windows Service a breeze by taking care of all the behind-the-scenes details after you’ve created your ordinary console application. There’s no need to worry about inheriting from the
ServiceBase class or needing to add a
ServiceProcessInstaller; merely, tell Topshelf what your service should be named and which methods Topshelf should call when the service is started and stopped, and you will get a console application that you can debug without going through all the usual hoops.
Hangfire is a library that allows you to add different kinds of background jobs to your ASP.NET projects. It supports a variety of background task types such as fire-and-forget, delayed, and recurring, without needing a separate Windows Service. It includes a beautiful, sleek dashboard so you can quickly get an overview of all jobs, running or failed. The library will also synchronize jobs on different machines.
By using AutoFixture for your unit testing, you won’t need mocks for peripheral dependencies in any given test. AutoFixture “auto-magically” creates anonymous variables and an instance of the system under test (SUT). As a result, adding a new parameter to the constructor of the SUT will not break any of your tests. If you integrate AutoFixture with other unit testing frameworks, you will receive a SUT instance and the other variables as test parameters, minimizing your test code even further.
Need to convert a Pascal case string to a readable sentence? Need to pluralize or singularize words? Convert numbers to words? Dates to a relative date or time spans to a friendly string? The Humanizer library “humanizes” your data, supporting English and almost forty other human languages.
AngleSharp is a library for parsing and manipulating HTML documents. It fully supports HTML5 and, just like browsers, it can handle malformed HTML. After parsing the HTML, it provides a DOM, which you can query with CSS selectors or filter with LINQ. The DOM is fully interactive, so you can remove or add new elements and the DOM will reflect the changes. AngleSharp is available as a Portable Class Library, making it usable for Xamarin and Windows Phone projects as well.
If you need to manipulate images in your app, ImageProcessor is your new best friend; it can resize, rotate, watermark, crop, apply various filters, and more, plus, it does so in a very efficient way. ImageProcessor’s fluent interface makes it easy to explore the API and its library does not depend on GDI+, so it also works on the .NET Core too.
Regular expressions (also known as RegEx) are powerful but they are hard to write, read and maintain in general. This is what VerbalExpressions tries to solve; it comes with a descriptive, fluent API which results in more expressive, easy to follow code. Just consider this ugly RegEx code to check if a string is a valid url:
var regex = new Regex(@"^(http)(s)?(://)(www\.)?([^\ ]*)$");
var isValidUrl = verbalExpression.Test("http://toptal.com");
Now, take a look at the corresponding VerbalExpression code that would replace it:
var verbalExpression = new VerbalExpressions()
MiniProfiler is a simple yet very powerful mini-profiler for ASP.NET. It profiles all your database commands, regardless of whether you use raw ADO.NET or an ORM, such as Linq-to-Sql or the Entity Framework. It includes neat functionality, such as explicitly profiling part of your code by wrapping it with a call to the
NoSql databases, such as RavenDb and MongoDb, are also supported, plus it has providers for ASP.NET MVC as well as WCF.