Author Archives: Andreas
FluentValidation Increment Collection By 1
mit {CollectionIndex} kann man in einer FluentValidation Message den Index ausgeben. Dieser beginnt aber mit 0, was für Entwickler normal ist, aber eben nicht für Anwender. Daher kann man mit dieser ExtensionMethod den Index +1 setzen, womit er mit 1 anfangen würden. Nachteil, man muss nach jeder .Message(„…“).IncrementCollectionIndexBy1() anhängen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static class IncrementCollectionIndexExtension { public static IRuleBuilderOptions<T, TProperty> IncrementCollectionIndexBy1<T, TProperty>(this IRuleBuilderOptions<T, TProperty> ruleBuilder) { return ruleBuilder.Configure(rule => { // A rule can only have a single message builder. // If it already has one, cache it and call it from within our new one below // (essentially chaining them together). rule.MessageBuilder = (context) => { if (context.MessageFormatter.PlaceholderValues.TryGetValue("CollectionIndex", out object index)) { if (index is int i) { i++; context.MessageFormatter.AppendArgument("CollectionIndex", i); } } return context.GetDefaultMessage(); //return rule.MessageBuilder?.Invoke(context) ?? context.GetDefaultMessage(); }; }); } } |

FluentAssertions replace with Shouldly
Just press cmd+H in Visual Studio and replace
1 2 3 |
Should(). with Should |
and
1 2 3 |
using FluentAssertions; with using Shouldly; |
99% percent of the errors should be gone. If you like to stay with FluentAssertions (which I do not recommend), open your .csproj file and put brackets around the version. This will prevent you upgrading to version 8
1 |
<PackageReference Include="FluentAssertions" Version="[7.0.0]" /> |
Rancher Desktop auf Windows installieren
Rancher Desktop wsl verschieben:
1 2 3 4 5 6 7 8 9 |
wsl --export rancher-desktop D:\rancher-desktop.tar wsl --unregister rancher-desktop wsl --import rancher-desktop D:\Docker\wsl\RancherDesktop "D:\rancher-desktop.tar" --version 2 wsl --export rancher-desktop D:\rancher-desktop-data.tar wsl --unregister rancher-desktop-data wsl --import rancher-desktop D:\Docker\wsl\RancherDesktopData "D:\rancher-desktop-data.tar" --version 2 wsl ~ -d rancher-desktop |
Autofac injecten
Da mich das eben ein paar Minuten gekostet hat, will ich das einmal festhalten. Folgendes NuGet muss im Projekt inkludiert sein: Autofac.Extensions.DependencyInjection HostApplication:
1 2 3 4 5 6 |
HostApplicationBuilder builder = Host.CreateApplicationBuilder(); builder.ConfigureContainer(new AutofacServiceProviderFactory(autofacBuilder => { })); |
WebApplication:
1 2 3 4 5 6 7 8 9 10 11 12 |
var builder = WebApplication.CreateBuilder(args); builder.Host .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureServices(services => { }) .ConfigureContainer<ContainerBuilder>(autoFacBuilder => { }); |
Docker auf Windows installieren ohne Docker Desktop
Die DockerCLI und DockerEngine sind Freeware und OpenSource, im Business Bereich muss die Docker Desktop Anwendung erworben werden. Um Docker nutzen zu können, braucht man nicht unbedingt Docker Desktop. Auch wenn Docker Desktop einem bei der Einrichtung vieles einfacher macht. Hier soll eine Schritt für Schritt Anleitung folgen Alle Schritte nutzen PowerShell oder meine Empfehlung […]
dotNet Docker veröffentlichen
die csproj bearbeiten:
1 2 3 4 5 6 7 8 9 |
<PropertyGroup> <EnableSdkContainerSupport>true</EnableSdkContainerSupport> <ContainerImageName>mein-container-name</ContainerImageName> <ContainerImageTag>1.0.0</ContainerImageTag> ... <ItemGroup> <PackageReference Include="Microsoft.NET.Build.Containers" Version="8.0.403" /> ... |
Docker Desktop muss vorinstalliert sein und mit wsl2 laufen
1 |
dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer -c Release |
Https Zertifikat für Entwicklung erstellen: https://learn.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-8.0#running-pre-built-container-images-with-https
1 2 |
dotnet dev-certs https -ep D:\Docker\https\aspnetapp.pfx -p 'GeheimesPassword' <span class="hljs-keyword">dotnet</span> <span class="hljs-keyword">dev-certs</span> https<span class="hljs-parameter"> --trust</span> |
Docker
Docker Desktop (AMD64) Docker Desktop: The #1 Containerization Tool for Developers | Docker In der Regel reicht auch nur die cli
1 2 3 4 |
choco install docker-cli --confirm choco install docker-engine --confirm Set-Service -Name docker -StartupType Automatic |
und Rancher Desktop
1 |
choco install rancher-desktop --confirm |
Portainer https://docs.portainer.io/start/install-ce/server/docker/wsl
1 |
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest |
WebAdmin: https://localhost:9443/ Microsoft Sql Server microsoft/mssql-server – Docker Image | Docker Hub
1 |
docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=XXXX" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest |
Passwort setzen nicht vergessen Im Container, unter volumes als bind, ein Verzeichnis […]
Logging Structured Message Templates selbst verwenden
Um selbst Strukturierte Messages Templates wie im Logging zu verwenden, kann man folgende Annotations nutzen:
1 2 3 4 5 6 7 8 |
[MessageTemplateFormatMethod("message")] public void Error<TArgument1, TArgument2, TArgument3>([Localizable(false)][StructuredMessageTemplate] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { if (IsErrorEnabled) { WriteToTargets(LogLevel.Error, message, new object[3] { argument1, argument2, argument3 }); } } |
Discord Installation „a fatal javascript error occurred“
Das war die einzige Lösung, die funktionierte, um Discord zu installieren über choco: I have a problem with discord, and its no the logo. : r/discordapp (reddit.com) Dazu das Powershell-Script. Ausprobiert und getestet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Get the Local AppData path dynamically using %LocalAppData% environment variable $localAppData = [System.Environment]::GetFolderPath('LocalApplicationData') $discordPath = Join-Path $localAppData "Discord" # Navigate to the Discord folder Set-Location -Path $discordPath # Delete the installer.db file if it exists $installerDbPath = Join-Path $discordPath "installer.db" if (Test-Path $installerDbPath) { Remove-Item $installerDbPath -Force Write-Host "Deleted installer.db file from $discordPath" } else { Write-Host "No installer.db file found to delete." } # Get the folder that starts with "app-" $appVersionFolder = Get-ChildItem -Path $discordPath | Where-Object { $_.Name -like 'app-*' } | Select-Object -First 1 # Check if the app version folder was found if ($appVersionFolder -ne $null) { $sourceDbPath = Join-Path $appVersionFolder.FullName "installer.db" # Check if the installer.db file exists in the app version folder if (Test-Path $sourceDbPath) { # Copy the installer.db file to the Discord folder Copy-Item -Path $sourceDbPath -Destination $discordPath -Force Write-Host "Copied installer.db from $($appVersionFolder.Name) to $discordPath" } else { Write-Host "No installer.db file found in $($appVersionFolder.Name)" } } else { Write-Host "No app version folder found." } |
Jupyter unter Windows installieren
Mit Jupyter (Julia + Python) kann man interaktive Notebooks erstellen. Ein Notebook besteht aus Cells, die entweder als Text (markdown) oder Code (Python, etc.) nacheinander erstellt werden können. Der Code kann im Notebook ausgeführt werden und visuell dargestellt werden. Variablen können Code-Zelle übergreifend genutzt werden. Damit der Code ausgeführt werden kann, wird ein Kernel benötigt, […]
Login