A simple notification management with Observer Design Pattern.

Hi All,

Observer pattern is one of the most common design pattern which we can see in C#. It simply creates a way for one component to notify other component that some changes happened. Here I am trying to implement a notification system using the observer pattern. My intention is to create a system which will have minimal change when a new notification mechanism is introduced to the system. Say today we are using an email system, tomorrow we got a requirement to add SMS, again new requirement came for wats app. Like that. All these changes should be smooth without impacting the current application structure.

Continue reading “A simple notification management with Observer Design Pattern.”

Setup PostgreSQL in Docker.

Hi,

In this document we will be seeing how we can setup a PostgreSQL in local machine using docker for development activities. The task is simple as we can see most of the commands in dockerhub. Lets see how we can do that.

First of all we should be familiar with docker and docker hub. I strongly suggest creating a docker hub free account. https://hub.docker.com/

Continue reading “Setup PostgreSQL in Docker.”

Difference between AddScoped, AddTransient and AddSingleton in dotnet core.

Hi all,

In this post what I am trying to discuss is a common concept in dotnetcore. I hope when reading this you have an idea of what dependency injection in C# is. If you dont have clear picture on that, please go ahead and refer more about those concepts. Because this post will be discussing few methods how dotnet core’s in built DI works.

When we explain about these methods, as a high level statement I would like to word the concept like below

Continue reading “Difference between AddScoped, AddTransient and AddSingleton in dotnet core.”

Extension methods in C#

Extension methods provide a way to extend the existing types in c#. For example suppose I need to extend the string class to add a method to fetch the first letter of the string variable, I can use Extension methods.

An extension method is a static method of a static class, where the “this” modifier is applied to the first parameter. The type of the first parameter will be the type that is extended.

Let’s see how we can achieve this.

Continue reading “Extension methods in C#”

Decoupling using Autofac IOC Container

Autofac is a a IOC(Inversion Of Control) Container for Microsoft .NET. It supports a wide array of application designs with very little additional infrastructure or integration code, and with a lower learning curve. Still it contains most of the features available in other DI containers.

Lets see how to use Autofac using a simple desktop application. Below are my interfaces and their corresponding implementations.

Continue reading “Decoupling using Autofac IOC Container”

Authentication and Authorization in ASP.Net Web API

Web API assumes that authentication happens in the host. For web-hosting, the host is IIS, which uses HTTP modules for authentication. You can configure your project to use any of the authentication modules built in to IIS or ASP.NET, or write your own HTTP module to perform custom authentication.

When the host authenticates the user, it creates a principal, which is an IPrincipal object that represents the security context under which code is running. The host attaches the principal to the current thread by setting Thread.CurrentPrincipal. The principal contains an associated Identity object that contains information about the user. If the user is authenticated, the Identity.IsAuthenticated property returns true. For anonymous requests, IsAuthenticatedreturns false.

In Web API, authentication filters implement the System.Web.Http.Filters.IAuthenticationFilter interface. They should also inherit from System.Attribute, in order to be applied as attributes.

The IAuthenticationFilter interface has two methods:

  • AuthenticateAsync authenticates the request by validating credentials in the request, if present.
  • ChallengeAsync adds an authentication challenge to the HTTP response, if needed.

Continue reading “Authentication and Authorization in ASP.Net Web API”

Common Table Expressions in SQL Server.

You might have came across a scenario for writing a recursive query in sql server. CTE(Common Table Expression) will help you for doing this. A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table Continue reading “Common Table Expressions in SQL Server.”

CRUD Operations using ASP.Net Web API and EntityFramework 5.0.0

As we know Web Api is becoming a new breakthrough in .Net programming. As per microsoft,

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

The advantages of Web Api are, Continue reading “CRUD Operations using ASP.Net Web API and EntityFramework 5.0.0”