Top libraries that make your life easier as a developer

If you are a developer this article is going to make your life easier. We are going to talk about third-party libraries that can help you as well as helps to make your code clean.

Third-Party Libraries

1. AutoMapper

AutoMapper helps to copy data from one object to another object type. AutoMapper does some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper established convention, almost no configuration is needed to map two types. With only one line of code, you can map 2 complex objects.

public class Person
{
    public string FirstName {get; set;}
    public string LastName  {get; set;}
}

public class Employee
{
    public string FirstName {get; set;}
    public string LastName  {get; set;}
}

var mapper = config.CreateMapper();
// or
var mapper = new Mapper(config);
Employee employee = mapper.Map<Employee>(person);

With this simple one line, you can easily map source and destination object. AutoMapper is a powerful library and can do more like mapping complex lists and more. It’s worth a try if you have not used it. You can check out the Nuget Package.

2. ReSharper

ReSharper is one of my personal favorites. The tool itself is very powerful which makes your life a lot easier as well as makes your IDE much better than before. ReSharper comes with lots of features like Code Analysis, Refactoring, Code Generation, Instant traversing, Compliance to a coding standard, and much more. The only part which hurts is this is a Paid tool. You can check out the pricing and discount here. In the end, I can say it’s totally worth it.

3. Fluent Validation

Fluent Validation is also one of the popular .NET library for validation. Fluent Validation is for building strongly-typed validation rules. With that you don’t have to write any complex validation every time in your code. With this you can avoid all dirty work in your code. The library is powerful enough to handle complex business rules and validation.

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
  }
}

So next time whenever you want to manage any complex rule or any validation do check out this library.

4. AutoFac

You must be aware of must of the core SOLID principle Dependency Inversion or Dependency Injection then this might help you Autofac is an addictive Inversion of Control container for .NET Core, ASP.NET Core, and more. I am not going to cover Dependency Injection in this article as this is out of scope. But If you have not used AutoFac, do give it a try!

5. Newtonsoft

If in your project you have to deal with JSON/XML Serialization or De-Serialization especially if you are working with APIs, this library is going to be very useful for you. Newtonsoft is an open-source library with that you can Serialize and deserialize any .NET object, Create, parse, query, and modify JSON using Json.NET’s JObject, JArray, and JValue objects. and much more. For the Nuget package check out this.

Hope this article helps you and makes your life easier. Let me know in the comments which are your favorite libraries.

Happy Coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: