Posts

Showing posts with the label .NET Core

Entity Framework Core Performance Optimization

Entity Framework Core Performance Optimization Last year I talked about Entity Framework Core . It is a easy and feature rich ORM which makes working with database in a .NET environment typesafe. But even though it makes things easy, there are ambiguous cases which can take us off guard. Today we will see four of this cases and how to deal with them. Client evaluation Iteration Include and ThenInclude NoTracking For the following examples, I will be using SQLite with Entity Framework Core. tl;dr Make sure that the query constructed in c# uses function that can be translated to SQL, Make sure that there isn’t an abnormal amount of queries created and that it does not iter item per item, Make sure to use Include and ThenInclude for object relation to include them after query execution, before query execution it is not needed, Use NoTracking for readonly queries to disable tracking on entity to yield better performance. 1. Client evaluation The following example illust...

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKE

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKE Last week we saw a flow to manage versioning and releases . As a continuation of last week, today I will show how we can setup versioning and releases for open source projects by configuring Appveyor and using FAKE to setup a build script. Configure AppVeyor FAKE 1. Configure AppVeyor Configuring AppVeyor is done via a yaml file appveyor.yml at the root of the repository. Then from the site https://www.appveyor.com/ , we can sign in with our GitHub credentials and add the repository to the AppVeyor projects. All the settings in the settings tab can be configured in the yaml file. appveyor.yml settings can be seen in multiple sections: global environment build test artifact deploy The global configuration is where we configure the context of the build, # 1. version: '{build}' image: Visual Studio 2017 skip_branch_with_pr: true skip_commits: files: - docs/**/* - ...

HTTPS with SSL for Nginx, Kestrel and Angular

HTTPS with SSL for Nginx, Kestrel and Angular Internet is moving toward secure connections whereby HTTPS is a priority. Browsers are now warning users when navigating to non secured website. With this movement, Kestrel and ASPNET Core have adopted the mentality of security by default rather than security when needed. HTTPS will now be the default and HTTP will be a necessity due to implementation constraints. Together with Lets Encrypt and ACME protocol, we do not have excuses for not implementing an SSL connection. Setup the example SSL self signed certificate for Nginx SSL self signed certificate for Kestrel SSL self signed certificate for Angular CLI 1. Setup the example We assume that our environment is on Ubuntu, with nginx and dotnet installed. If you are on Windows, you can install the linux subsystem with Ubuntu 16.04 as describe on my previous post . This will give access to most of the features of Ubuntu via a bash prompt. To start we create a HelloWorld applicatio...

Verify dotnet SDK and runtime version installed

Verify dotnet SDK and runtime version installed To check your dotnet version installed, use dotnet --info . This command will display the SDKs and runtimes installed on your system together with the path where they can be found. For example on my Windows 10 development machine, dotnet --info will yield the following: > dotnet --info .NET Core SDK (reflecting any global.json): Version: 2.1 . 301 Commit: 59524873 d6 Runtime Environment: OS Name: Windows OS Version: 10.0 . 17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\ 2.1 . 301 \ Host (useful for support): Version: 2.1 . 1 Commit: 6985 b9f684 .NET Core SDKs installed: 2.1 . 4 [C:\Program Files\dotnet\sdk] 2.1 . 201 [C:\Program Files\dotnet\sdk] 2.1 . 300 [C:\Program Files\dotnet\sdk] 2.1 . 301 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1 . 0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.A...

Multi environment logging with Serilog for AspNet Core

Multi environment logging with Serilog for AspNet Core Few months ago we saw how to get started with Serilog. We discovered what was Serilog and the different concepts of settings, enrichers and sinks. Today we will see how we can take Serilog further and configure a logging mechanism for an application running in multi environment. Setup Serilog Multi environment AWS CloudWatch 1. Setup Serilog If you have never seen Serilog before you can start with my previous post on How to get started with Serilog . In order to configure our first logging mechanism, we start by creating an AspNet Core application and install Serilog , Serilog.AspNetCore and the sinks we will be using Serilog.Sinks.Console , Serilog.Sinks.File . RollingFile sink also exists but it has been superseded with File sink. Next we can configure the logger to write to Console and write to a file: public static IWebHost BuildWebHost(string[] args) { return WebHost.CreateDefaultBuilder(args) ...

Custom Minio Grain Storage for Microsoft Orleans

Image
Custom Minio Grain Storage for Microsoft Orleans Grains states in Orleans are stored in a grain storage. Orleans ships with multiple highly available storage implementation like Azure blob storage or AWS Dynamodb. Today we will see how we can implement our own grain storage which will store grains on Minio , an open source free private cloud storage. Implement a simple blob storage abstraction and implementation with Minio Implement grain storage interface Register the grain storage 1. Implement a simple blob storage abstraction and implementation with Minio internal interface IMinioStorage { Task<bool> ContainerExits(string blobContainer); Task CreateContainerAsync(string blobContainer); Task<Stream> ReadBlob(string blobContainer, string blobName, string blobPrefix = null); Task UploadBlob(string blobContainer, string blobName, Stream blob, string blobPrefix = null, string contentType = null); Task DeleteBlob(string blobContainer, string blobNam...

ASP NET Core with Nginx

ASP NET Core with Nginx Few weeks ago I showed how to host ASP NET Core on Windows Server behind IIS. Compared to Windows Server, Ubuntu with nginx offers a quicker way to get started and a better control over the kestrel process. Today we will see how to host an ASP NET Core application on Ubuntu. This post will be composed of three parts: Install nginx Configure nginx Host ASP NET Core 1. Install nginx Start by installing nginx. sudo apt-get update sudo apt-get install nginx After installing nginx, the daemon should have been installed and started. We should be able to navigate to http://localhost and see the nginx default page. This page is the default root folder of nginx which can be found under /var/www/html/ . We should also be able to interact with it just like any other daemon managed by systemd : sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl status nginx And similarly it can be debugged via journald : sudo jo...

ASP NET Core Client-side libraries management with VS 2017 Library Manager

Image
ASP NET Core Client-side libraries management with VS 2017 Library Manager Few weeks ago I discussed how we could create a healthchek library which would return json status of our application. Using the json, I wanted to make a quick page to display healthchecks in a nice visual. I wanted to quickly add Bootstrap and momentJS . For frontend libraries, I was used to use Bower as it nicely put every frontend package in /bower_components which can be served as static data. But since Bower was announcing that it was no longer supported and requested to use Yarn or NPM, I started to look around for an easier solution than those as I don’t really care about source code of the frontend libraries, all I want is the latest compiled versions. After few minutes of research, I found out that the team in Microsoft felt the same way as I did and already worked on a tool called Library manager (libman) and is available in VS Preview for the moment. Libman gives the benefit to allow developers t...