Posts

Showing posts from 2020

.Net Core Dependency Injection - Quick Use Guide

Hi all, we all know now, .Net Core supports Dependency Injection (DI) out of the box. Ok, so let's see how to use it in this quick use guide. For test this out let's create 2 projects (give names as you like); Worker service project - I called it MailSender Class library - and I named this as MailManager Let's use the DI: 1. Create a class in MailManager  I created a class called MailConfigurator.cs Create a method called GetData inside that class. 2. Open the Program.cs of your Worker Service project. Then lets define the scope and register our dependency in the dependency container: public static IHostBuilder CreateHostBuilder(string[] args) =>             Host.CreateDefaultBuilder(args)                 .ConfigureServices((hostContext, services) =>                 {                     services.AddSingleton<MailConfigurator>();                     services.AddHostedService<Worker>();                 }); NOTE: There are 3 service lifetimes; Transient, Sco

Apache ActiveMQ 5 with .Net Core 3.1 and C#

Image
Hi All..   In this post I'm going to explain how to use Apache ActiveMQ 5 (which is a popular Java based messaging server) for .Net Core 3.0+ with C#.  Let's get started. Prerequisites 1. Visual Studio (I'll be using 2019 Community)  2. .Net Core framework (I'll be using 3.1) 3. Java JDK or JRE Installed and Java Environment variable has been set (Since I'm doing in a Windows 10 computer)  Ok.. If you have the above requirements then let's get start the actual work. 1. Download and install ActiveMQ 5  Go to http://activemq.apache.org/components/classic/download/ and download according to your operating system.  I'll download .zip package for Windows 2. Copy the .zip file and put it inside a folder as you like or install with the installers if you download the installer.  If you got the .zip file like me; then extract it inside the folder that you paste the .zip file Then you will get a folder with the ActiveMQ package  3. Start the Active MQ Server  Open th

How well your code doing? - Visual Studio Code Metrics

Image
Today when I completed my work, I just curious how many lines of code that I have wrote so far. So I search how to calculate the lines of code and I found Visual Studio Code Metrics: A very valuable information source about your code and your solution. So I went little more deeper to understand what all these counts mean. And I was so interested with my findings and I thought I have to share these with you. I think this is a very cool and important feature of Visual Studio. So how to view these numbers? Simple, just navigate to Analyze  →  Calculate Code Metrics  And it will give you some numbers according the number of project that you have in your solution. In my case there are 8 project and here are my results: Ok, let's see what are these calculations and what are these numbers are and most importantly what are those mean to you. Maintainability Index This index shows how easy or hard to maintain or modify your code. This will give a number between 0-100 and colo

Using Angular Material in an angular app with some best practices

Image
Angular Material is a UI component library for angular. Ok let's see how do you use this within an angular application using some of the best practices. Prerequisites 1. Code editor (Ex: VS Code) installed 2. Node.js installed 3. Angular cli installed ( https://cli.angular.io/ ) I think you already know how to create a new angular application with Angular cli. If you can't remember lets create a new angular app. 1. Create an angular app Open the terminal and user command: ng new [name of your app] 2. Install angular material Navigate inside your app with command prompt and run command: ng add @angular/material When it prompts to install: 1. HammerJs for Gesture recognition: Select Yes 2. Setup browser animations: Select Yes 3. Create a module to hold angular material components By creating a dedicate module for this will help to import all the required angular material components that we are going to use in the app within this module. Then we can im

Deploy Angular 8 app to Azure with Azure DevOps

Image
1. Create a Azure Web App. Use the following Configurations:      Runtime Stack: ASP.NET V4.7      Operating System: Windows You can select your own subscription plan, resource group and region.  2. Create a Git repository to hold the Angular app 2.1. Initialize your angular application 2.2. Commit and Push the code.  3. Create a Pipeline in Azure DevOps.  3.1. Login to the Azure DevOps. ( https://dev.azure.com/ ) 3.2. Create a project:          I'll select Private as visibility and Git as Version control.  NOTE: Azure DevOps provides different features.               For this task we are going to focus on Pipelines.  4. Pipeline Part 1: Integrate Git  From the Connect section select: Use the classic editor. 4.1. Select a Source as GitHub and authenticate with your GitHub account using OAuth.  4.2. Select your repository which holds the angular app. 4.3. Select the branch. This is the branch that Azure DevOps will