Skip to content

Instantly share code, notes, and snippets.

View xiaomi7732's full-sized avatar
🌴
On vacation

Saar Shen xiaomi7732

🌴
On vacation
View GitHub Profile
@xiaomi7732
xiaomi7732 / SetupMSSQLExpressInContainer.md
Created November 2, 2024 01:43
A tutorial to run MS SQL Express in a container, and access it in local box

Run SQL Express in a Container

Key Highlights

  • Run the Free Version: Easily deploy MSSQL Express in a Docker container using Docker Desktop.
    • You don't need Docker Desktop if you are on Linux.
  • Local Access for Development: Set up the container to be accessible as if SQL Server were installed directly on your machine.
  • Data Persistence: Ensure that your data is saved to a local folder for easy access and management.

Ready to get started? Check out the full guide here: Setup SQL Express in a Container

@xiaomi7732
xiaomi7732 / DeployNetAppWithArmTemplates.md
Last active August 24, 2024 01:10
Deploy .NET 8 to Linux Azure App Service, Slot and Auto Swap Using ARM Templates
@xiaomi7732
xiaomi7732 / AsyncBeforeHostStart.md
Created March 1, 2024 05:34
Run Async code before hosting get started
@xiaomi7732
xiaomi7732 / aspnetcorefilterparameters.md
Last active October 10, 2023 21:29
How to Create ASP.NET Core Filter with Parameters

Accept the parameter on the attribute

using Microsoft.AspNetCore.Mvc;

namespace FiltersDemo;

public class ExampleFilterAttribute : TypeFilterAttribute
{
    public ExampleFilterAttribute(AnEnum enumValue) : base(typeof(ExampleFilter))
@xiaomi7732
xiaomi7732 / HttpStatusCode.md
Last active September 22, 2023 21:13
HTTP Status Code & Typical Usage

HTTP Status Code & Typical Usage

This page will be used to note down different commonly used status code and the scenarios.

Http Status Code: 200 OK

200 OK, which means it succeeded.

Typically used as a response for synchronous operations.

@xiaomi7732
xiaomi7732 / SpecialRouteValuesInCreateAtAction.md
Created August 10, 2023 01:35
Handling Special Characters in RouteValues for CreatedAtAction

Handling Special Characters in RouteValues for CreatedAtAction

When working with ASP.NET and the CreatedAtAction method, the process of providing route values is often straightforward. Consider the following example:

[HttpPost]
public async Task<IActionResult> Post(ApiVersion apiVersion)
{
    ...
 var routeValues = new 
@xiaomi7732
xiaomi7732 / ReplaceService.md
Created August 8, 2023 00:02
How to replace a service in C# dependency injection

How to replace a service in C# dependency injection

Discover the Power of the Replace Method!

Unveil the hidden gem within C# dependency injection – the Replace method – to effortlessly update services. Experience the simplicity firsthand:

Suppose you're aiming to substitute the initial singleton service of IAnalyzer with the innovative SimpleAnalyzer implementation. Behold the elegance of the solution:

services.Replace(ServiceDescriptor.Singleton());
@xiaomi7732
xiaomi7732 / HashStringToGuid.md
Created August 3, 2023 00:05
Hash a string to a guid

Hash a string to a guid

Sometimes, you may encounter a situation where you require a GUID-formatted key but only have a loose string at hand. In such cases, this simple solution can prove to be quite effective.

Goal

This is the API I want:

Guid CreateGuid(string value);
@xiaomi7732
xiaomi7732 / ApiVersionAttribute.cs
Created July 31, 2023 21:04 — forked from commonsensesoftware/ApiVersionAttribute.cs
Implement Custom API Version Format
public sealed class ApiVersionAttribute : Asp.Versioning.ApiVersionAttribute
{
public ApiVersionAttribute( string version )
: base( CustomApiVersionParser.Default, version ) { }
public ApiVersionAttribute( string token1, string token2, string? token3 = default )
: base( new CustomApiVersion( token1, token2, token3 ) ) { }
}
@xiaomi7732
xiaomi7732 / LinkFile.md
Created July 26, 2023 23:54
Link a file in csproj for compiling

Needs to do this from time to time.

  <ItemGroup>
    <Compile Include="..\ServiceProfiler2\src\ServiceProfiler.Analysis.DataModels\Insights\InsightRecord.cs" Link="InsightRecord.cs" />
  </ItemGroup>