Tuesday, August 28, 2018

Visual C# Technical Guru - July 2018

Another month as a judge in Microsoft TechNet Guru Awards under Visual C# category. The TechNet Guru Awards celebrate the technical articles on Microsoft TechNet.

image
Visual C# Technical Guru - July 2018
Happy Coding.

Regards,
Jaliya

Monday, August 27, 2018

What’s New with ASP.NET Core 2.2 Preview 1

ASP.NET Core 2.2 has beginning to shape up and is expected to be released before the end of this year.

If you want to try out some of the features, ASP.NET Core 2.2 Preview 1 is already released. As soon as you have the following running in your machine, you are all good to explore those.
image
ASP.NET Core 2.2
Following are the features of ASP.NET Core 2.2 Preview 1.
  • Template Updates: Use of Bootstrap 4, Angular 6 and clean up most of the boilerplate code)
image
Cleaned Up Templates
  • IIS In-process hosting
Right now, when an ASP.NET Core application is hosted in IIS, when a request is made, it’s being forward from w3wp.exe (known as IIS Worker Process) to dotnet.exe via Inter-Process Communication (IPC). This seems to have performance implications and ASP.NET Core team is trying to improve the performance by moving ASP.NET Core logic into IIS Worker Process itself.
  • Web API Conventions
  • HTTP/2
  • Endpoint Routing
  • Health Checks
  • SignalR Java Client

Check out
ASP.NET Core 2.2 Roadmap for more information.

That’s exciting, isn’t it.

Happy Coding.

Regards,
Jaliya

Wednesday, August 8, 2018

Docker: Windows Server 2016, ASP.NET Core 2.1 Runtime Image with Node

I wanted to have a docker image with Windows Server 2016 having ASP.NET Core 2.1 Runtime and Node installed, and didn’t find any official image that has them all (maybe there is and it’s just I couldn’t find).

But managed to get one created with some little extra steps.
# escape=`
# The escape directive sets the character used to escape and it's used both to escape characters in a line, 
# and to escape a newline. Below we have some commands spanning across multiple lines, so we need this.
# Note: It needs to be menioned before anything, yes, even before a comment.
 
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-nanoserver-sac2016
 
# The default shell on Windows is ["cmd", "/S", "/C"], Changing to PowerShell
SHELL["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
 
# Current Node LTS Version as of 07/08/2018
ENV NODE_VERSION 8.11.3
 
# Make sure to use the SHA of the specified Node version 
ENV NODE_VERSION_SHA 91b779def1b21dcd1def7fc9671a869a1e2f989952e76fdc08a5d73570075f31
 
# PowerShell commands to download and extract  
RUN Invoke-WebRequest https://nodejs.org/dist/v$Env:NODE_VERSION/node-v$Env:NODE_VERSION-win-x64.zip -OutFile node.zip; `
    if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $Env:NODE_VERSION_SHA) { `
        Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
        exit 1; `
    }; `
    `
    Expand-Archive node.zip -DestinationPath node-temp; `
    Move-Item node-temp/node-v$Env:NODE_VERSION-win-x64 $Env:ProgramFiles/nodejs; `
    Remove-Item -Force node.zip; `
    Remove-Item -Force node-temp
 
# Setting Node to Path
RUN setx /M PATH $($Env:PATH + ';' + $Env:ProgramFiles + '/nodejs')
 
# Next steps is omitted

Hope this helps someone having the same requirement.

Happy Coding.

Regards,
Jaliya

Wednesday, August 1, 2018

Rest Parameters in TypeScript

In TypeScript, Rest Parameters are often used in functions to specify the parameters when the number of parameters is unknown.

Let’s go by a sample scenario. Imagine we need to have a method which will return us the full address (nicely separated by “,”) when different parts of the address are supplied. Some addresses have Address Line 1, Address Line 2 etc., and for some, there is no Address Line 2, likewise.

In this case, there is no fixed number of parameters. To cater such a requirement, we can have the following function with Rest Parameters.
function buildAddress(...addressLines) {
    return addressLines.join(", ");
};
Here the Rest Parameter is the addressLines, we are using JavaScript split operator (ellipsis) to specify that.

With TypeScript it’s always better to be explicit. You can specify the type of the Rest Parameters as well. And note, it should always be an array type as behind the scene it really is an array.
function buildAddress(...addressLines: string[]) {
    return addressLines.join(", ");
};
We can call the function like below.
console.log(buildAddress("111-2222", "Bing Street", "Springfield Gardens", "NY", "33333"));
// 111-2222, Bing Street, Springfield Gardens, NY, 33333

console.log(buildAddress("111-2222", "Springfield Gardens", "NY", "33333"));
// 111-2222, Springfield Gardens, NY, 33333
And you can even not pass anything at all.
console.log(buildAddress());
Isn’t it nice!

Happy Coding.

Regards,
Jaliya