Upgrade ASP.NET Core and Entity Framework Core 2.0 to 2.1-preview1

In the past weeks we have upgraded our ASP.NET Core 2.0 project to 2.1-preview. The main reason for the upgrade is using the latest signalr capabilities and hosted services. The issues we had are related to the features we use. In our case the upgrade encountered some minor issues. In this blog post I’ll show what we had to change and give some tips on how to upgrade.

Continue reading “Upgrade ASP.NET Core and Entity Framework Core 2.0 to 2.1-preview1”

Advertisements

Initialize ASP.NET Core 2 with CreateDefaultBuilder, what differs if you run in Development enviroment

Knowing the differences when you run your application in a Development environment

When building asp.net core 2 web applications, most projects are initializing Kestrel with the CreateDefaultBuilder. If you use this extension method to configure Kestrel, it is good to know what is set and what differs when you are running a Development configuration or any other configuration. In practice there are two differences. In this blog I’ll explain the two differences.

Continue reading “Initialize ASP.NET Core 2 with CreateDefaultBuilder, what differs if you run in Development enviroment”

ASP.NET Core background processing

Run background processes with the IHostedService and how to inject your services with dependency injection

Many services need background processing. The ASP.NET Core 2 IHostedService interface gives you an easy implementation skeleton to implement background processes. The Hosted Services are registered in the dependency injection at startup and started automatically. You do not have to do the pluming to get them started at startup. On shutdown you can implement a graceful shutdown. When running background processes there a few pitfalls to avoid. In this blog I’ll introduce the IHostedService and how to avoid common memory leaks when implementing the hosted service.
Continue reading “ASP.NET Core background processing”

Cannot access a disposed object in ASP.NET Core when injecting DbContext

Find the root cause of what really happened to you disposable object.

Working with ASP.NET core I have seen this error multiple times and can be hard to debug. The error can have multiple root causes. It can be a real pain to find the cause and it is sometimes fixed by only taking care of the symptoms. By finding the root cause, you can take the appropriate action in your code.

Continue reading “Cannot access a disposed object in ASP.NET Core when injecting DbContext”

Set custom timeout for code first Migrations Entity Framework (Core 2.0)

Allow customizing timeout for migrations.

Sometimes a migration takes more time then your default timeout of your database connection. In such a case you do want to increase the timeout for the migration to be able to complete, but you do not want to change the timeout for your normal operations.
Continue reading “Set custom timeout for code first Migrations Entity Framework (Core 2.0)”

Add Index with Include Entity Framework (Core 2.0)

Add index with inlude in EF Core 2.0 code first migrations

When creating indexes with code first migrations in Entity Framework Core 2.0 you can create an index on a table by adding the following to your DbContext:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity
<Table>()
        .HasIndex(t => new { rrs.Column1, rrs.Column2});
}

Continue reading “Add Index with Include Entity Framework (Core 2.0)”

ASP.NET Core correct usage of ConfigureAwait with async/await

Lately we had a discussion on when to use ConfigureAwait(true) or ConfigureAwait(false) in ASP.NET Core 2. In the end most of the team, including me, had a faulty assumption on how to do this in ASP.NET Core. In this case ASP.NET Core is different from ASP.NET. Good to know if you have to decide on what to use in ASP.NET core.

Continue reading “ASP.NET Core correct usage of ConfigureAwait with async/await”