Showing posts from 2017

Microsoft Orleans logs warnings and errors

Microsoft Orleans logs warnings and errorsMicrosoft Orleans is a framework which helps building distributed system by implementing the actor model together with the concept of virtual actors, taking care of availability and concurrency. If you are unfamiliar with Microsoft Orleans, you can look at my previous blog post explaining the benefits of Microsoft Orleans. Even though Orleans promises to abstract the distributed system problems, there are instances where errors arise without us being able to understand what is going on. Lucky us, the logs are well documented… but only for those who can decrypt them.
Today I will go through some of the errors and warnings which can be seen from silo and client so that you too can undestand what is going on. Enjoy!The code used to produce those errors can be found on my GitHub Client logsLogs on client appears with address {ip}:0.1.1. Can’t find implementation of interfaceAn unhandled excepti…

How to setup Continuous Integration/Deployment with GitLab for ASP NET Core application

How to setup Continuous Integration/Deployment with GitLab for ASP NET Core applicationIn any application, Continuous Integration and Continous Deployment environments are important to setup to remove respectively the risking of breaking your application while pushing code to master branch and having to manually deploy your application each time you need to either test it or deliver it. GitLab comes with a set of features to integrate quickly CI/CD to your application for free!
Today we will see how we can setup CI/CD by leveraging the free services from GitLab.
This post will be composed by 4 parts:1. Overview of the scenario 2. Setup a runner 3. Configure your job 4. Monitor your deployment on GitLab 1. Overview of the scenarioThe example that I will take is an ASP NET Core application which runs as a Windows service.My scenario is the most simplistic one may have:I want to setup CI, meaning build and running test and detect break in my code at each push to master branch,I want to s…

Prime NG data table for Angular

Prime NG data table for AngularIn every web application there is a need to display data in a tabular form. If the amount of data is small, a simple combination of HTML with Bootstrap is enough. But when the data is large, or more advanced functionalities are needed like sort or pagination, a more elaborated table needs to be used. If you followed me, you must have noticed that I am a huge fan of Prime NG and once again, Prime NG saves us the burden of implementing a complex data table by providing an Angular component fully featured. Today we will see how to use it in 3 parts:1. Use Prime NG data table 2. Customized cell template 3. Pagination All the source code for this example is available on my GitHub.1. Use Prime NG data table1.1 Basic usageStart by installing Prime NG.npm install primeng --save Then in your main app module, register the DataTableModule to get access to its components.@NgModule({ imports: [ ... other imports DataTableModule ], ... other configuratio…

Validation in ASP NET Core and Angular

Validation in ASP NET Core and AngularValidation is an important part of any application. There are two parts where validation is required, the API level and the frontend. The API validation is meant to prevent any malformed input to corrupt our data while the frontend validation is meant to guide the user to fill in a form by providing interactive feedback on her input. ASP NET Core for the backend and Angular for the frontend both ship with validation mechanisms fulfilling are requirements. Today we will see how we can implement validation in ASP NET Core using data annotation and inline validation with Angular reactive form. This post will be composed by 2 parts:1. Implement validation for ASP NET Core 2. Implement inline validation for Angular form 1. Implement validation for ASP NET CoreIn ASP NET Core, validation can be implemented using data annotation. On each call, parameters are tested against the annotation and the ModelState property is filled up.
When any of the parameter…

Implement PATCH on ASP NET Core with JSON Patch

Implement PATCH on ASP NET Core with JSON PatchWhen building web APIs, most of the HTTP methods are implemented, GET, POST, PUT, PATCH and DELETE. While GET, POST and PUT are easily implemented, PATCH functionality is slightly different as it allows to change one or more properties of the resource. It is used to patch the resource. One way to do it is to use a protocol called JSON Patch. Today we will see how we can use JSON Patch through the ASP NET Core implementation and how we can construct the request from the frontend. This post will be composed by 3 parts:1. JSON Patch protocol 2. Implementation on ASP NET Core 3. Usage from frontend in TypeScript 1. JSON Patch protocolJSON Patch
is a protocol defining a format expressing operations to be applied on JSON objects.The operations are composed by the following object:{ op: '', path: '', value: '' } op being the operation, path being the path of the property of the JSON object and lastly value being the value…

REST - Representational State Transfer

REST - Representational State TransferSince the past 5 years, there has been an increasing demand to know how to build RESTful Web Services. Never had a job interview for Software Engineering failed to include at least one question about REST or RESTful Web Services and never a week passed with at least hearing one comment like “if we do x, it will not be RESTful”. Everyone seems to be on top of it, know everything about REST.
But is it true? Do they really know REST? How certain can one be that her system is RESTful?
Today I would like to share my point of view about REST by going through three points:1. Overview 2. How does REST link with HTTP protocol 3. What have we learnt 1. OverviewCountless time, I have seen the following:A: Do you know REST? B: Yes A: Can you write the URLs for a REST API for a user profile? B: Ok, there; GET /profiles GET /profiles/123 POST /profiles PUT /profiles/123 PATCH /profiles/123 DELETE /profiles/123 A: Perfect This…

Swagger for ASP NET Core API development

Swagger for ASP NET Core API developmentBuilding a web API is not an easy task. In order to build one easy to use, we need to consider the routes, the HTTP methods, the return results from the endpoints, the parameter used for the body of the requests, etc…
Swagger is a tool which compiles all our API endpoints into a friendly GUI and allows us to directly test them. It brings a lot of benefits as we can easily pinpoint mistakes in the endpoints route or parameters and of course in the implementation since we can straight away call the endpoints.
Today we will see how we can integrate Swagger in 3 parts:1. Add Swagger to ASP NET Core project 2. Handle authentication 3. Handle endpoints specificities with filters 1. Add Swagger to ASP NET Core projectWe start first by creating an empty ASP NET Core project with the following startup:public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } public void Configure(IA…

Silo configuration and Cluster management in Microsoft Orleans

Silo configuration and Cluster management in Microsoft OrleansFew weeks ago we saw how to create a Silo and how to implement grains. We also saw how we could create an ASP NET Core web app to talk to the Silo. We discovered the benefits of the single threaded model in grains. Today we will see one of the other major feature of Orleans, cluster management. This post will be composed by 3 parts:1. Build a silo 2. Form a cluster with multiple silos 3. Cluster management with membership All the source code can be found on my GitHub. Build a siloLet’s start first by implementing a Silo. We will be using the example we used in the past post.public class Program { public static void Main(string[] args) { var silo = new SiloHost("main"); silo.InitializeOrleansSilo(); var success = silo.StartOrleansSilo(); if (!success) { throw new Exception("Failed to start silo"); …

Microsoft Orleans Grains Concurrency Handling

Microsoft Orleans Grains Concurrency HandlingFew weeks ago I explained the benefits of using Microsoft Orleans. One of them was the implementation of the actor pattern. Today I will dig deeper into it by revisiting a common scenario present in today systems and how it can be solved with Orleans grains.
This post will be composed by 3 parts:1 - Traditional system 2 - The problems 3 - Grain solution 1. Traditional systemIn a traditional system, we can often see a N-tier architecture (usually 3-tier) composed by the following:Front end -> Service tier -> Database The front end being the webserver like ASP NET. The service tier being a set of stateless services containing business logic. They ensure the consistency of the system by extracting the latest state of business object from the database, validate business rules and write back to database ~ the last tier. In this sort of architecture, the database is the source of truth.This can be illustrated with the following example of a…

Create a simple Microsoft Orleans application

Create a simple Microsoft Orleans applicationLast week I presented an overview of Microsoft Orleans. Gave an explanation on the concepts and keywords which can be found in the framework.
Today I will explain how we can implement a simple Orleans application with a cluster composed by a localhost Silo and with a client within an ASP Net Core Mvc application.
This post will be composed by 3 parts:1. Implement the grains 2. Create the silo 3. ASP Net Core Mvc client 1. Implement the grainsThe grains are the unit of work in an Orleans application. They contain the business logic and ensure that the state is consistent.
In our example we will be implementing a Bank account grain with a withdraw and deposit functionality. There will be a single business rule being that the balance of any account cannot be lower than 0.We start first by creating the grain interface in a project where we reference Orleans.Core.public interface IBankAccount: IGrainWithStringKey { Task Deposit(double a); …