Skip to content

Category: .Net Core

Build and Deploy an ASP .Net Core Web Application as Docker Container using Microsoft Azure – Part 1

This article is the first in the series where we are going to build a simple ASP .Net Core web application, containerize it with Docker and run it on local host. And we will push everything to GitHub for later use.In later posts, we will setup Microsoft Azure DevOps Build pipeline to automate the process of building and pushing the Docker image to Docker Hub. Next, we will use Azure DevOps Release pipeline to deploy our application on Azure Web App Service as a container.

A better approach to use HttpContext outside a Controller in .Net Core 2.1

Introduction In my previous post we discussed an approach to access the HttpContext.Session in RequestHandler. However, there was a problem. For every single component where we need to access the session, we have to inject a dependency of IHttpContextAccessor. While for one or two components it’s not a problem, it can be very daunting if we have to do the same over and over again. In this article, we will use a different…

Using HttpContext outside a Controller in .Net Core 2.1

  Introduction Last Friday, while working on a web application based on ASP.Net Core 2.1, I came across a scenario where I had to put some data into memory. While that’s not a problem, the catch is that the data has to be unique for each Http Session. Consider it as keeping a key that is to be used across different views to display some…

Null Object Pattern

Almost every method that we write, irrespective of the programming language, we always have checks like the following one: if (objectVariable == null) return; // do some work with objectVariable We end up adding so many null checks in our methods, that it gets almost hard to figure out what we are supposed to do in our method. This makes our code look ugly and hard…

Anonymous Types in C#

Generally, for an object to encapsulate some properties, the type of the object has to be defined first. On the contrary, anonymous types provide a convenient way for an object to encapsulate readonly properties without explicitly defining the type first. The type of each property is deduced by the compiler.   Creating an Anonymous Type We can create an anonymous type using a new keyword along…

When to use “var” as a Type

Introduction It has been quite a long time since var was introduced, yet it stands debatable among .net developers. Everyone has a different understanding as and when to use var as a type. A couple of days ago I was also a part of one such discussion, and so I decided to share my understanding. CodeProject   Readability Every developer has all the right to use var as and…