Programming Tips 💡
54.5K subscribers
65 photos
8 videos
30 files
338 links
Programming:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact & Ads: @MoienTajik
Download Telegram
Using the ReferenceAssemblies NuGet package to build .NET Framework libraries on Linux, without installing Mono 💎

In this post I show how you can build .NET projects that target .NET Framework versions on Linux, without using Mono! 🤷🏻‍♂️

By using the new Microsoft.NETFramework.ReferenceAssemblies NuGet packages from Microsoft you don't need to install anything more than the .NET Core SDK! 🔥


[ Article ] : kutt.it/coremono

〰️〰️〰️〰️〰️〰️
#CSharp #DotNet #AspCore #NetCore
@ProgrammingTip
EasyCompressor 📦

EasyCompressor is an open-source compression abstraction library that supports and implements many compression algorithms such as Zstd, LZMA, LZ4, Snappy, Brotli, GZip and Deflate. 🗂

It is very useful for using along with Distributed Caching or storing files in database.

[ GitHub ] : github.com/mjebrahimi/EasyCompressor

〰️〰️〰️〰️〰️〰️
#Compression #CSharp #DotNet
@ProgrammingTip
Blazor WebAssembly 3.2.0 now available 🚀

I’m thrilled to announce that Blazor WebAssembly is now officially released.

This is a fully-featured and supported release of Blazor WebAssembly that is ready for production use.

Full stack web development with .NET is now here! ⚡️

[ Article ]: https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-now-available/

〰️〰️〰️〰️〰️〰️
#Blazor #DotNet #Core
@ProgrammingTip
Secrets of a .NET Professional 👾

In this post, we’ll go through technical and non-technical ideas that have helped me through some of my toughest projects.

[ Article ] : https://kutt.it/DotSec

〰️〰️〰️〰️〰️〰️
#DotNet
@ProgrammingTip
Awesome Microservices .NET Core Resources 😎

The best resources for Microservices in .NET Core 👾

[ Github ] : kutt.it/dotnet-aws

〰️〰️〰️〰️〰️〰️
#DotNet #DotNetCore #AspNetCore #Microservice
@ProgrammingTip
Looking inside ConfigurationManager in .NET 6

ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code. 🧹

However ConfigurationManager is very much an implementation detail. It was introduced to optimise a specific scenario (which I'll describe shortly), but for the most part, you don't need to (and won't) know you're using it.

In this post, We take a look at the ConfigurationManager class, why it was added, and some of the code used to implement it.


[ Article ] : https://kutt.it/cfg-mgr

〰️〰️〰️〰️〰️〰️
#DotNet #AspNetCore
@ProgrammingTip
Nuke Build 🗂

As C# developers, we are spoiled with a great language and awesome IDEs.

Why do most automation systems never really match the level of convenience and integration that we're used to?

NUKE is different. 💎

It is fully based on C# console applications and uses the type system to its full extent.

You want your auto-completion, package management, debugging, refactorings, formatting, and navigation back? It’s available right there❗️


[ Website ] : https://nuke.build/
[ GitHub ] : github.com/nuke-build/nuke

〰️〰️〰️〰️〰️〰️
#CSharp #Dotnet #BuildSystem
@ProgrammingTip
Source Link 🐞

Source Link is a language- and source-control agnostic system for providing first-class source debugging experiences for binaries.

The goal of the project is to enable anyone building NuGet libraries to provide source debugging for their users with almost no effort.

Microsoft libraries, such as .NET Core and Roslyn have enabled Source Link.

Source Link
is supported by Microsoft.

〰️〰️〰️〰️〰️〰️
#DotNet #CSharp #Debugging
@ProgrammingTip
ChilliCream GraphQL Platform 🌶

The ChilliCream GraphQL Platform, at its core, is a new way to create powerful Backends. HotChocolate, .NET GraphQL server, connects any service or data source and creates a cohesive service to offer your consumers a unified API. 💎

Hot Chocolate: GraphQL server to create GraphQL endpoints and merge schemas.

Banana Cake Pop: GraphQL IDE to explore, request and analyze any GraphQL endpoint. 🌐

Strawberry Shake: GraphQL client to fetch data from any GraphQL endpoint. 🔁

Green Donut: DataLoader to solve the N+1 problem. 🔂


[ GitHub ] : github.com/ChilliCream/hotchocolate

〰️〰️〰️〰️〰️〰️
#GraphQL #DotNet #AspNetCore
@ProgrammingTip
aspnetcore-developer-roadmap.png
606.9 KB
ASP.NET Core Developer Roadmap in 2023 🔝

Roadmap to becoming an ASP.NET Core developer in 2023 🚀

[ GitHub ] : https://github.com/MoienTajik/AspNetCore-Developer-Roadmap

〰️〰️〰️〰️〰️〰️
#AspNetCore #DotNet #DotNetCore #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
WireMock.NET 😮

WireMock.NET is a .NET library for stubbing and mocking HTTP services. With WireMock.NET, you can define the expected responses for particular requests, and the library will intercept and manage those requests for you. ✔️

This allows for easy testing of the code that makes HTTP requests, without having to rely on the actual external service being available and without hacking HttpClient. 🆒

Sample code snippet:

[Test]
public async Task sample_WireMock_usage()
{
// Setup WireMock.Net server
using var wireMock = WireMockServer.StartWithAdminInterface(port: 1080, ssl: false);

// Setup WebApplicationFactory
await using var appFactory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration(configurationBuilder =>
{
// Override downstream service addresses pointing to WireMock address
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
["ExternalServices:WeatherService"] = "http://localhost:1080"
});
});
});

// Prepare stub for outgoing request
wireMock
.Given(
Request.Create()
.WithPath("/api/v1.0/weather")
.WithParam("lat", "10.99")
.WithParam("lon", "44.34")
.UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithBodyAsJson(new
{
temp = 298.48,
feels_like = 298.74,
temp_min = 297.56,
temp_max = 300.05,
pressure = 1015,
humidity = 64
})
);

// Automate tested app
}


[ Blog ] : https://cezarypiatek.github.io/post/mocking-outgoing-http-requests-p1

〰️〰️〰️〰️〰️〰️
#UnitTest #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Check out new C# 12 preview features! ⚡️

Three new features for C# 12 😮 :

1️⃣- Primary constructors for non-record classes and structs :
public class Student(int id, string name, IEnumerable<decimal> grades)
{
public Student(int id, string name) : this(id, name, Enumerable.Empty<decimal>()) { }
public int Id => id;
public string Name { get; set; } = name.Trim();
public decimal GPA => grades.Any() ? grades.Average() : 4.0m;
}


2️⃣- Using aliases for any type:
using Measurement = (string, int);

public void F(Measurement x)
{ }


3️⃣- Default values for lambda expression parameters:
var addWithDefault = (int addTo = 2) => addTo + 1;
addWithDefault(); // 3
addWithDefault(5); // 6


[ Article ] : https://devblogs.microsoft.com/dotnet/check-out-csharp-12-preview

〰️〰️〰️〰️〰️〰️
#CSharp #DotNet
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
.NET 8 - Keyed service dependency injection container support 🔝

Keyed services are useful when you have an interface/service with multiple implementations that you want to use in your app. What's more, you need to use each of those implementations in different places in your app. ☄️

Sample:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedSingleton<INotificationService, SmsNotificationService>("sms");
builder.Services.AddKeyedSingleton<INotificationService, EmailNotificationService>("email");
builder.Services.AddKeyedSingleton<INotificationService, PushNotificationService>("push");


[ Article ] : https://andrewlock.net/exploring-the-dotnet-8-preview-keyed-services-dependency-injection-support

〰️〰️〰️〰️〰️〰️
#DotNet #DotNetCore #AspNetCore #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Introducing .NET Aspire: Simplifying Cloud-Native Development with .NET 8 🔥

.NET Aspire is an opinionated stack for building resilient, observable, and configurable cloud-native applications with .NET. It includes a curated set of components enhanced for cloud-native by including service discovery, telemetry, resilience, and health checks by default. 👍


Sample Usage:
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedisContainer("cache");

var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithReference(cache)
.WithReference(apiservice);

builder.Build().Run();



[ Article ] : https://devblogs.microsoft.com/dotnet/introducing-dotnet-aspire-simplifying-cloud-native-development-with-dotnet-8

〰️〰️〰️〰️〰️〰️
#DotNET #AspNetCore #CSharp #Aspire
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
🔍 Challenge: Create a compact Maze Game in C# under 2KB without .NET Runtime, Small enough to fit in a QR Code 🤔

👨‍💻 Process:
• Self-Contained: Includes all necessary components to run on any OS. ✔️

• Game Type: A graphical maze, utilizing Win32 APIs, avoiding WinForms. ⭐️

• Size Reduction Steps:
1- Initial Size: 64MB (with CoreCLR)
2- Post-Compression: 35.2MB
3- IL Trimming Applied: 10MB
4- Native AOT Compilation: 1.13MB
5- Removing Unused Features: 923KB
6- Using bflat Compiler: 882KB
7- bflat with Zerolib: 9KB
8- Direct PInvoke: 8KB
9- Eliminating Debugging and Relocations: 7KB
10- Targeting x86 Architecture: 6.5KB
11- Final Step with Crinkler Linker: 1,936 Bytes

🎉 Outcome: Achieved a C# game small enough to fit in a QR code!


[ Full Article 🔗 ] : https://migeel.sk/blog/2024/01/02/building-a-self-contained-game-in-csharp-under-2-kilobytes

〰️〰️〰️〰️〰️〰️
#CSharp #DotNet #Optimization #LowLevel
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Introducing WireMock.NET: Master HTTP API Testing 🚀

WireMock.NET simulates HTTP API behaviors, enabling seamless integration and testing for developers.

👌 Ideal Use Cases:

HTTP Dependencies Not Ready: Leap over the hurdle of incomplete HTTP APIs in microservice architectures by mimicking their behavior with WireMock.Net.

Unit Testing HTTP-Dependent Classes: Test classes that rely on HTTP APIs as a cohesive unit, ensuring your code communicates effectively with the actual APIs.

Integration/End-to-End Tests: Overcome the challenges of testing with external HTTP APIs—like variable data, slow responses, and network restrictions—by employing WireMock.Net for consistent and swift testing.


public class ExternalService(HttpClient httpClient)
{
public async Task<string> GetAsync()
{
var response = await httpClient.GetAsync("/ping");
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStringAsync();
}
}

public class ExternalServiceTests
{
[Fact]
public async Task GetAsync_WhenCalled_ReturnsString()
{
// Arrange
var fakeServer = WireMockServer.Start();

fakeServer
.Given(Request.Create().WithPath("/ping").UsingGet())
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("pong")
);

var fakeClient = fakeServer.CreateClient();
var externalService = new ExternalService(fakeClient);

// Act
var response = await externalService.GetAsync();

// Assert
response.Should().Be("pong");
}
}



[ GitHub ] : https://github.com/WireMock-Net/WireMock.Net

〰️〰️〰️〰️〰️〰️
#DotNet #WireMock #IntegrationTest
@ProgrammingTip
🚀Ready to Track Your Application with Metrics? 📊

Looking to keep a close eye on your ASP.NET Core applications? With the latest update in .NET 8, you can now easily track various aspects of your application's performance and health through built-in metrics.

Here's why it's exciting:

HTTP Request Insights: Get a detailed view of your HTTP requests, including counts, durations, and more.

• Real-time Alerts: Set up alerts to notify you if your app's performance exceeds predefined thresholds.

• Error Handling Diagnostics: Pinpoint and address issues faster with detailed error handling diagnostics.

User-friendly .NET Aspire Dashboards: Access a user-friendly dashboard through .NET Aspire, making it easy to visualize and understand your app's metrics.

Customizable Grafana Dashboards: Dive deep into your app's performance with customizable Grafana dashboards, tailored specifically for ASP.NET Core metrics

Excited to learn more? Dive into the details and revolutionize your app monitoring experience! 💻💡

[ Article ] : https://devblogs.microsoft.com/dotnet/introducing-aspnetcore-metrics-and-grafana-dashboards-in-dotnet-8/

〰️〰️〰️〰️〰️〰️
#DotNet #Metrics #Grafana #Dotnet_Aspire #Monitoring
@ProgrammingTip
5 Rules for Writing Better and Cleaner DTOs 🧹

Crafting clean and maintainable DTOs is essential for keeping your codebase healthy and scalable. But let's face it, sometimes DTOs can morph into these complex beasts that leave you scratching your head.  ‍

Fear not, fellow developers!

This article (or the accompanying video!) dives into 5 key principles to help you write simpler, more understandable DTOs.

You'll learn about:

• Keeping things clear and concise
• Utilizing properties effectively
• Crafting descriptive names that make sense

And also other tips to transform your DTOs from chaotic to crystal clear! By following these principles, you'll be well on your way to writing cleaner, more maintainable DTOs that make your code easier to understand for you and your team.

Ready to up your DTO game? Check out the full article or watch the video for examples and take your codebase to the next level!

[ Article ] : https://ardalis.com/5-rules-dtos

[ YouTube ] : https://www.youtube.com/watch?v=W4n9x_qGpT4

〰️〰️〰️〰️〰️〰️
#Dto #Dotnet #csharp #programming
@ProgrammingTip
OpenAI .NET 👾

The OpenAI .NET library provides convenient access to the OpenAI REST API from .NET applications. ✔️

The full API of this library can be found in the api.md file, and there are many code examples to help. For instance, the following snippet illustrates the basic use of the chat completions API:

ChatClient client = new(model: "gpt-4o", "OPENAI_API_KEY");

ChatCompletion completion = client.CompleteChat("Say 'this is a test.'");

Console.WriteLine($"[ASSISTANT]: {completion}");


The library is organized into several namespaces corresponding to OpenAI feature areas. Each namespace contains a corresponding client class:

AssistantClient
AudioClient
BatchClient
ChatClient
EmbeddingClient
FineTuningClient
FileClient
ImageClient
ModelClient
ModerationClient
VectorStoreClient


[ GitHub ] : https://github.com/openai/openai-dotnet

〰️〰️〰️〰️〰️〰️
#AI #OpenAI #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM