Skip to content

Instantly share code, notes, and snippets.

View Robbware's full-sized avatar
🏠
Working from home

Robbware Robbware

🏠
Working from home
  • Lisbon
  • 15:30 (UTC)
View GitHub Profile
@Robbware
Robbware / UriExtensions.cs
Created May 27, 2024 23:16
UriExtensions.AddParameterIfNotNull
public static class UriExtensions
{
/// <summary>
/// Adds the specified parameter to the Query String.
/// </summary>
/// <param name="url"></param>
/// <param name="paramName">Name of the parameter to add.</param>
/// <param name="paramValue">Value for the parameter to add.</param>
/// <returns>Url with added parameter.</returns>
public static Uri AddParameterIfNotNull(this Uri url, string paramName, string paramValue)
@Robbware
Robbware / DependencyInjectionHelper.cs
Created December 4, 2023 22:49
IServiceCollection extension to add all types of a particular type within the same assembly
using Microsoft.Extensions.DependencyInjection;
public static class DependencyInjectionHelper
{
public static IServiceCollection AddByType<T>(this IServiceCollection serviceCollection, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
var types = typeof(T).Assembly.GetTypes()
.Where(x => !x.IsAbstract && x.IsClass && x.GetInterface(typeof(T).Name) == typeof(T));
foreach (var type in types)
@Robbware
Robbware / blazorsassisolation.md
Last active September 5, 2022 15:47
Blazor - Get component isolated SCSS files compiled into CSS and ready for Blazor CSS isolation to work

If you don't have npm initialized in your project scope, run npm init -y

  1. npm install sass --save-dev Refer to: https://sass-lang.com/documentation/

  2. Add, to your package.json, on the scripts object: "scripts": { "sass": "sass" },

  3. Create a new folder Styles, with an app.scss file there - this'll be your global styling solution

  4. On your project's .csproj, add:

@Robbware
Robbware / outdated.md
Last active August 29, 2022 15:27
Quickly discover if you have any outdated NUGET packages

Install tool: dotnet tool install --global dotnet-outdated

Usage: On the solution/project folder, run dotnet outdated

@Robbware
Robbware / AddMigration.ps1
Created June 27, 2022 20:11
Creates a .NET Core migration, with a specific migration project and a specific startup project.
param([string]$Name)
if([string]::IsNullOrEmpty($Name)) {
Write-Host "Fill in your migration name.";
return;
}
$MigrationProject = "";
$StartupProject = "";