Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
manoj-choudhari-git / KeyedServicesDemoDI.cs
Created March 4, 2024 07:08
.NET 8 - Keyed Services Registration Demo
public static class DependencyRegistrationBootstrapper
{
public static void RegisterDependencies(this IServiceCollection services)
{
// Register three implementations
services.AddKeyedTransient<IReminderService, SmsReminderService>(ReminderType.Sms);
services.AddKeyedTransient<IReminderService, EmailReminderService>("Email");
services.AddKeyedTransient<IReminderService, PushNotificationReminderService>(ReminderType.PushNotifications);
}
}
@manoj-choudhari-git
manoj-choudhari-git / controller.cs
Created December 13, 2023 16:28
.NET 8 Keyed Services - One Interface Multiple Implementations - Ways to Resolve Implementations
// ---------------------------------------------------------------------------------
// DEMO 1 - Inject using FromKeyedServices attribute
// ---------------------------------------------------------------------------------
[Route("api/[controller]")]
[ApiController]
public class FirstController : ControllerBase
{
// This should be email service implementation
private readonly IReminderService reminderService;
@manoj-choudhari-git
manoj-choudhari-git / demo.cs
Created December 13, 2023 16:23
.NET 8 Keyed Services Demo - An Example - One Interface - Multiple Implementations
public enum ReminderType
{
Email,
Sms,
PushNotifications
}
//---------------------------------------------------------------------------------
// One Interface - Three Implementations
//---------------------------------------------------------------------------------
@manoj-choudhari-git
manoj-choudhari-git / samplewebapi-scan.ps1
Created September 26, 2023 22:07
Demo - Sample Commands For SonarQube Scan of .NET Project
## --------------------------------------------------------------------------------
## STEP 1 - INSTALL DOTNET-SONARSCANNER (One Time Setup)
## --------------------------------------------------------------------------------
dotnet tool install --global dotnet-sonarscanner
## --------------------------------------------------------------------------------
## STEP 2 - BEGIN ANALYSIS
## --------------------------------------------------------------------------------
dotnet sonarscanner begin /k:"sample-web-api" /d:sonar.token="sqa_1s2s3om4t5o6k7e8e9n"
@manoj-choudhari-git
manoj-choudhari-git / sonarqube-scan.ps1
Created September 26, 2023 21:38
SonarQube - To Trigger SonarQube Scan of a .NET Solution
## --------------------------------------------------------------------------------
## STEP 1 - INSTALL DOTNET-SONARSCANNER (One Time Setup)
## --------------------------------------------------------------------------------
## To install dotnet sonarscanner tool globally (latest version)
## You can also specify the version you want to install using --version argument
dotnet tool install --global dotnet-sonarscanner
## --------------------------------------------------------------------------------
## STEP 2 - BEGIN ANALYSIS
## --------------------------------------------------------------------------------
@manoj-choudhari-git
manoj-choudhari-git / elastic-search.sh
Created September 21, 2023 22:21
SonarQube Local Instance Setup - Commands to enable Elastic Search in docker image
wsl -d docker-desktop
sysctl -w vm.max_map_count=524288
sysctl -w fs.file-max=131072
ulimit -n 131072
ulimit -u 8192
@manoj-choudhari-git
manoj-choudhari-git / compose.yaml
Created September 21, 2023 21:49
Docker Compose Yaml - To Compose SonarQube Instance
version: "3"
services:
sonarqube:
image: sonarqube:community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
@manoj-choudhari-git
manoj-choudhari-git / delete-stale-branches.ps1
Last active September 19, 2023 23:29
PowerShell Script - To Automate Clean up of Stale Branches From Remote Repository
################################################################
## Note: This script should be executed
## from the machine where the remote repository is cloned.
################################################################
## Parameter is_dry_run, defaulted to true to avoid deletion by mistake
## Invoke Command - "$ delete-stale-branches.ps1 -is_dry_run $true"
param([Boolean]$is_dry_run = $true)
##---------------------------------------------------------------
@manoj-choudhari-git
manoj-choudhari-git / cleanup-local-git-branches.ps1
Created September 14, 2023 21:24
Git - PowerShell Script to Clean up Local Merged Branches
## Checkout the main branch
## If your main branch name is different, use that name instead of 'main'
git checkout main
## This will remove the branches
## which are present on local but are deleted on remote
git fetch --prune
## The below command will get all branches which are merged
## Then it will remove the names 'main', 'master', 'develop' from the list
@manoj-choudhari-git
manoj-choudhari-git / azure-devops-create-branch.ps1
Last active August 16, 2023 10:36
Azure DevOps - Create A New Branch In Git Repository
$devopsApiVersion = "7.0"
$newBranch = "sprint/userStoryNumber";
$baseBranch = "master";
$organization = "contoso";
$project = "contoso";
$repository = "contosowebapp";
## -----------------------------------------------------------------
## Create Branch
## -----------------------------------------------------------------