Skip to content

Instantly share code, notes, and snippets.

View DilanLivera's full-sized avatar
💻

Dilan Waduge DilanLivera

💻
View GitHub Profile
@DilanLivera
DilanLivera / kibana_visualizations.md
Last active February 28, 2023 11:39
Kibana Visualizations
@DilanLivera
DilanLivera / how_to_install_prism_cli_as_a_windows_service.md
Created March 6, 2023 04:36
How to install Prism CLI as a Windows service

How to install Prism CLI as a Windows service

This note is regarding how to install Prism CLI as a Windows service. Prism CLI has a mock command which takes an API document and creates a mock server from the API documentation. The mock server will run until the shell windows stay open. By installing Prism CLI as a Windows service, we can keep the service running in the background.

How to install the service

  1. Install NSSM

    > choco install nssm -y
@DilanLivera
DilanLivera / how_to_enable_w3c_distributed_tracing_to_asp_dot_net_core_application.md
Last active March 6, 2023 05:50
How to enable W3C distributed tracing to ASP.Net Core application

How to enable W3C distributed tracing to ASP.Net Core application

.Net Activity library supports using W3C trace identifiers

    public class Program
    {
        public static void Main(string[] args)
        {
            Activity.DefaultIdFormat = ActivityIdFormat.W3C; //need to apply this as soon as the application starts
 CreateHostBuilder(args).Build().Run();
@DilanLivera
DilanLivera / _set_up_elasticsearch_and_kibana_using_docker.md
Last active March 6, 2023 05:54
Set up Elasticsearch and Kibana using docker
@DilanLivera
DilanLivera / how_to_customize_automatic_http_400_badRequest_error_response.md
Last active March 6, 2023 05:56
How to customize automatic HTTP 400 BadRequest error response

How to customize automatic HTTP 400 BadRequest error response

services.AddControllers()
        .ConfigureApiBehaviorOptions(options =>
        {
            options.InvalidModelStateResponseFactory = context =>
            {
                var problemDetails = new ValidationProblemDetails(context.ModelState)
 {
@DilanLivera
DilanLivera / HealthCheckResponses.cs
Last active March 6, 2023 05:59
How to implement a custom health check response writer
public static class HealthCheckResponses
{
public static Task WriteJsonResponse(HttpContext context, HealthReport report)
{
context.Response.ContentType = "application/json; charset=utf-8";
var options = new JsonWriterOptions { Indented = true };
using var writer = new Utf8JsonWriter(context.Response.BodyWriter, options);
@DilanLivera
DilanLivera / CustomEndpointBehavior.cs
Last active March 6, 2023 06:06
How to log WCF client requests and responses and Add MessageInspectors to EndpointBehaviour
//Add more than one inspector to an EndpointBehavior
public class CustomEndpointBehavior : IEndpointBehavior
{
private readonly List<IClientMessageInspector> _messageInspectors;
public CustomEndpointBehavior(List<IClientMessageInspector> messageInspectors)
{
_messageInspectors = messageInspectors ?? throw new ArgumentNullException(nameof(messageInspectors));
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
@DilanLivera
DilanLivera / a_simple_azure_ci_cd_pipeline_for_a_azure_function.md
Last active March 6, 2023 06:19
A simple Azure CI/CD pipepline for a Azure function

A simple Azure CI/CD pipepline for a Azure function

@DilanLivera
DilanLivera / how_to_secure_azure_functions_http_triggers.md
Last active March 6, 2023 06:21
How to secure Azure functions HTTP triggers

How to secure Azure functions HTTP triggers

HTTP triggers let you use API keys to block unknown callers by requiring the key to be present on each request. When you create a function, you select the authorization level. By default, it's set to "Function", which requires a function-specific API key, but it can also be set to "Admin" to use a global "master" key, or "Anonymous" to indicate that no key is required. You can also change the authorization level through the function properties after creation.

Since we specified "Function" when we created this function, we will need to supply the key when we send the HTTP request. You can send it as a query string parameter named code, or as an HTTP header (preferred) named x-functions-key.

@DilanLivera
DilanLivera / how_to_fix_npm_start_not_starting_the_react_app_issue.md
Last active March 6, 2023 06:23
How to fix npm start not starting the React app issue

How to fix npm start not starting the React app issue

Context

npm start command does not start the react app after creating the react app using npx create-react-app my-app command or using Visual Studio React templace for .Net Core

Problem

npm had been configured to ignore scripts