What You Need to Know about ASP.Net Core

ASP.net core uses .net core as its framework

First and foremost, ASP.net Core is built around .net core which means you now have the ability to develop and deploy ASP.net apps in other Operating Systems such as in Mac and in Linux which gives us larger options in terms of looking for our own server.

Since .net core is independent from Microsoft ecosystem, this gives you the ability to have a total control of the environment on where you will develop or deploy the application. Though, sadly, this hardly matters nowadays due to the advent of cloud technologies like aws, MS Azure, etc. which gives you the option to run different Operating Systems in their servers.

.net core is lighter compared to .net framework

This should pose no surprise to any developer who’s been playing with .net core for quite some time now. .net core has lighter footprint due to the fact that it’s now decoupled from .net framework and is an independent framework altogether. Which means, this doesn’t have lots of code dependencies(such as dlls) that came from .net framework and it’s codebase is still small.

In an ideal scenario, .net core wins than .net framework when it comes to performance.

These guys tried to benchmark the performance of ASP.net core in contrast with ASP.net 4.6.

The findings were astonishing and fascinating. It caters 1.15 million Requests Per Second which is a miles away from ASP.net 4.6 which only caters around below 200k requests!

It’s just a matter of what do you prefer for your team development needs.

ASP.net core uses MVC as its default web architecture

The Microsoft-dependent version of ASP.net uses two web architecture as its default template: Webforms and MVC.

In ASP.net core, this was no longer the case as Microsoft intended to get rid of Webforms either way. But there are some rumors that they’re trying to add support webforms for developers who still wants to use webforms as their web architecture.

Though personally, I’d try to stay away from Webforms if I were you. For your sanity’s sake.

[Route("/api/vehicles")]
public class VehiclesController : Controller {
    private readonly IMapper mapper;
    private readonly IVehicleRepository vehicleRepository;
    private readonly IUnitOfWork unitOfWork;
    public VehiclesController(IMapper mapper, IVehicleRepository vehicleRepository, IUnitOfWork unitOfWork)
    {
        this.vehicleRepository = vehicleRepository;
        this.mapper = mapper;
        this.unitOfWork = unitOfWork;
    }

    [HttpPost]
    [Authorize]
    public async Task<IActionResult> CreateVehicle([FromBody] SaveVehicleResource vehicleResource)
    {
        if (!ModelState.IsValid)
            return BadRequest(ModelState);

        // var model = await context.Models.FindAsync(vehicleResource.ModelId);
        // if (model == null)
        // {
        //     ModelState.AddModelError("ModelId", "Invalid Model ID");
        //     return BadRequest(ModelState);
        // }

        var vehicle = mapper.Map<SaveVehicleResource, Vehicle>(vehicleResource);
        vehicle.LastUpdate = DateTime.Now;

        vehicleRepository.Add(vehicle);
        await unitOfWork.CompleteAsync();

        vehicle = await vehicleRepository.GetVehicle(vehicle.Id);

        var result = mapper.Map<Vehicle, VehicleResource>(vehicle);

        return Ok(result);
    }
}

Also, it’s worth pointing out that Web API and MVC were already combined as one instead of a separate structure altogether. So, it’s better, cleaner, and less confusing. When I was starting out my ASP.net MVC journey, I was confused between the two and why Microsoft decided to create another template for MVC (Web API) which is just essentially structured as..well..MVC!

ASP.net core projects support npm(Node Package Manager)

If you’re familiar and a big fan of nodejs, then make no mistake: You can use npm alongside nuget package manager! Now you can use either package managers which suits your needs. Although you could also use npm to ASP.net MVC 5, but you will need to configure the project so that it aligns with npm’s structure and make their packages work. It’s worthy to note that npm is independent and used alongside javascript frameworks like Angular 4.

This is perhaps one of the big advantage ASP.net core has over traditional ASP.net. With npm, using javascript libraries, frameworks has never been this easier.

But sadly, if you understand the pain of setting everything up together to make npm packages work seamlessly on front-end side, then I don’t have to explain everything.

ASP.net core implements their own Dependency Injection containers

What a relief! It was like waking up from a bad dream.

I swear I was one of the few people that hates setting up IoC/DI containers like StructureMapNinject and Unity Container to inject dependencies in different controllers. If you’re a beginner in IoC/DI containers and just starting out using those containers I just mentioned, then I know for certain that it’s quite frustrating to set them up especially when you’re the type of developer that just wants to start coding your MVP for the people to see!

And this is a good news! No too much overhead. And not too much setup is needed for you to start reaping the benefits and use Dependency Injection in the repositories you need to use and reuse in every controllers that exist.

public void ConfigureServices(IServiceCollection services)
{
    // Register application services.
    services.AddScoped<ICharacterRepository, CharacterRepository>();
    services.AddTransient<IOperationTransient, Operation>();
    services.AddScoped<IOperationScoped, Operation>();
    services.AddSingleton<IOperationSingleton, Operation>();
    services.AddSingleton<IOperationSingletonInstance>(new Operation(Guid.Empty));
    services.AddTransient<OperationService, OperationService>();
}

There are 3 ways you can inject a dependency:

  • Scoped
  • Transient
  • Singleton

These methods depict and determines the lifetime of the dependency that you were trying to inject in each controllers where you used it.

The Bad

If there’s a good side then surely there’s also a bad side in learning and using ASP.net core in your projects. They say if there’s a Pros then there’s also some Cons.

I’ll enumerate them:

It’s brittle

Even after .net core 1 was released, developers were still reporting numerous bugs in github repository of ASP.net core. And a couple of times I run into few issues such as missing dependencies, current .net core version irrelevant in latest packages, etc. Though I understand the reason behind it. And I have to admit: .net core updates moved so fast.

There are instances where I left the project for a week, but after I hit dotnet restore, everything gets broken.

Entity Framework Core hasn’t grown mature enough as well. When I tried to associate a table into one-to-many relationship, where the table should have two or more data, EF Core migration doesn’t pluralize the table by default. So it’s not quite intelligent as of the moment.

Good news is, since it’s open-sourced, we will know the development status and stages of ASP.net core. You could also contribute to this awesome piece of repository.

Lots of developers around the world can now contribute in shaping ASP.net core unlike before.

Library support is still lacking and backwards compatibility might not be supported anymore

We all use nuget package manager to install the libraries we wanna use for our MVC apps. When I wanted to integrate a Unit Test within the app, I usually install NUnit package alongside NSubstitute for my mock objects.

When I wanted to implement Dependency Injection, I usually install Structuremap within my app.

If you’re dependent on those then you’re out of luck. .net core’s backward compatibility is still unstable and as of .net core 2.0, I heard rumors and seen some articles that you’re not allowed to use .net framework libraries anymore. Some project gets broken after upgrading to .net core 2.0. So you might wanna consider not using ASP.net core to your bigger projects at hand.

Anjali Punjab

Anjali Punjab is a freelance writer, blogger, and ghostwriter who develops high-quality content for businesses. She is also a HubSpot Inbound Marketing Certified and Google Analytics Qualified Professional.