inner-banner-cots

Development does not happen on one single platform in today’s environment. Microsoft .NET has evolved in the last two decades to allow for a full cross platform development. Microsoft has introduced .NET Core to its .NET ecosystem, a fork from existing .Net Framework to develop a new framework that is very much portable across various platforms.

Applications targeting .NET Core can easily run on Windows, Linus and macOS, at the same time Microsoft is committed to keep as an open source platform model. Microsoft .NET Core framework should not be viewed as a replacement to .NET framework. Applications using Windows Presentation Foundation (WPF), Workflow Foundation (WF), Windows Forms and other libraries not currently supported by .Net core will continue to use .NET Framework.

Core Framework

Microsoft .NET Core framework was released in 2016. It is another major milestone on the .NET ecosystem to enable cross platform applications. As of writing this article, Core supports ASP.NET Core and UWP and has recently added Entity Framework to supported list. The list will grow as it gets matured in the future. Because Microsoft is committed to keep .NET Core as open source, you can get the source code on GitHub at the following location: https://github.com/dontnet/core

Hosting .Net Core

Similar to .Net Framework, .NET Core needs a host to start the runtime. Microsoft .NET Core comes with a default host called “dotnet.exe” for application using .NET core. At the same time, you can write our own host executable depending on the needs.

Versioning

In a traditional .NET framework, you can install only the major versions of .Net framework side by side. For instance, it is possible to run Framework version 4.7 with 2.0 but at the same time Framework does not allow to run 4.7.1 and 4.6 on the same computer. Using .NET Core, it is possible to run multiple minor versions of Framework at the same time without the need to worry about any breaking changes.

Development

The very first thing you need to develop an application on .NET Core is the Framework. It can be downloaded the from this location: https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md. This link provides executables for Runtime as well as SDK targeting Windows, macOS, Linux and Ubuntu.  If you are looking for an IDE, Microsoft does offer Visual Studio Community Edition free for individual developers. Version 2017 can be downloaded at the following link: https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15

 

Testing Cross platform

In order to test the application across platform, let’s start with creating a hello world program. In the demo program, we are going to prompt the user name and print a text to the console. First, open the VS IDE and select Console App (.NET Core) project as shown below.

VS IDE

 

Select Program.cs and add the following lines to the Main entry point.

Console.WriteLine(“Please enter your Name:”);

var name = Console.ReadLine();

Console.WriteLine(“Hello” + name);

Console.WriteLine(“Press any key to exit…”);

Console.ReadKey(true);

The above code is going to ask for the name and print back your name. It then waits for a key entry before exiting.

If you do not see .NET Core 2.0 on the “Target Framework” you are probably missing the update for Visual Studio. Please go to “Extensions and Updates” and look for the latest update.

image2

Once installed, .NET Core 2.0 will start to show up on the dropdown.

image3

Now, go ahead and publish the application as we normally do.

image4

Now let’s discuss about two ways of building .NET Core application. First is to target OS with .NET framework installed. If you want to target OS without framework, you can go with building a self-contained application. On self-contained application, your application acts as host and does not require “dotnet.exe” to host your app.

To create a self-contained .NET Core application, we are going to edit the solution file by providing the list of Runtime Identifier (RID) as shown below

<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>

This will make the publisher to create self-contained application depending on the Runtime Identifier. The complete list of RID can be found at the following link: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog

image5

Now, go to publish screen again and click on “settings” link. Here we can choose the target, I am going to select either Windows, macOS or Ubuntu.

Please note that if you are using VS 2017 update 15.5.x, only way to build Windows is to use PowerShell because of a bug which is going to be fixed with 15.6 release.

To publish via PowerShell, use the dotnet publish command as shown below

image6

Here is the output on a Windows 10 64-bit machine.

image7

Now, I am going to test the version on an Ubuntu machine. For that I am going to rely on a ubuntu docker container. I will be writing a blog on Dockers next month, please sure to look for Docker setup and running containers on my blog.

I will start with Ubuntu 14.04, a docker image from docker hub. I then map my published files from Visual Studio to the running instance of Ubuntu.

image8

At time point, HellpWorldApp needs execute permission, the permission can be changed by issuing CHMOD command. Now I am all set to run the application on Ubuntu OS. Hurray!

image9

Microservices Architecture

On a traditional services architecture, the services layer contains pretty much all the functionality of the application with references to libraries and core components. On Microservices architecture, in contrast, the services layer is broken down into multiple autonomous components for easy management.

Each microservice is responsible to manage its own data model in a stateless manner. One of the reason, Microservice is getting lot of attention is because of its nature to allow for implementation using various technologies that can communicate via API across service boundaries.

Benefits

Microservices architecture provides a variety of benefits.  Here are the few benefits with this approach:

  1. Zero downtime deployment
  2. Reliable uptime
  3. Scalable
  4. Rapid growth/development
  5. Technology freedom
  6. Ownership
  7. Cloud/Container friendly
  8. Team optimization
  9. Business isolation
  10. Improved Quality & testing

Though Microservices offer various advantages, it does come with drawbacks. Because we are dealing with distributed SOA, the application will face a lot of new challenges that we do not generally face on monolithic applications. Not all applications are suitable for Microservices architecture. Proper design principles like Observable can help to address the drawbacks with Microservices.

It can be difficult at times to build Microservices because of its distributed computing model.  Microsoft introduces Service Fabric to ease development of Microservices. Service Fabric is a platform to build & deploy services taking some of the complexities and quickly addresses the cons with Microservices.

Service Fabric

As with any framework, we are going to start with SDK install to prepare for development of Service Fabric using Visual Studio. In my case I am using Visual Studio 2017 as my IDE. Download Service Fabric SDK from https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started . Alternatively, you can use Web Platform installer to install the SDK.

image10

Open VS 2017 and expand Cloud templates. Select “Service Fabric Application” as shown below.

image11

Select ASP.NET Core

image12

Select Web API

image13

Once you click “OK” Visual Studio will create a nice simple Microservice project.

image14

Before you run the application, configure your local cluster to 5 nodes by clicking the orange star wheel.

image15

Click F5 and Visual Studio will do all the hard work for you. It will deploy the service as you can see on the build output.

image16

Here is the “MyService” Microservice.

image17