Skip to content

Instantly share code, notes, and snippets.

View chivandikwa's full-sized avatar
🏆
winning

Thulani Chivandikwa chivandikwa

🏆
winning
View GitHub Profile
@chivandikwa
chivandikwa / PropsSetToStateInCtor.tsx
Created June 6, 2019 21:17
An example of incorrect usage of props to set state in ctor. When component rerenders the ctor will not be run again and any mutations to props will not be reflected in current state.
import React, { useState, useEffect } from "react";
import "./App.css";
const App: React.FC = () => {
const [user, setUser] = useState({ name: "john", email: "john.doe@test.zw" });
useEffect(() => {
setTimeout(() => {
setUser({ name: "jane", email: "jane.doe@test.zw" });
}, 500);
@chivandikwa
chivandikwa / SimpleInjectorOptionalDependencyUnregistered.cs
Created June 7, 2019 18:52
Simple injector does not resolve types that have unregistered dependencies even when they are optional
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using SimpleInjector;
namespace SimpleInjectorNullableConstructor
{
internal interface ISample
{
}
@chivandikwa
chivandikwa / MicrosoftBotFrameworkWithSimpleInjector.cs
Created June 8, 2019 11:38
Replace Microsoft.Extensions.DependencyInjection.IServiceCollection with SimpleInjector in Microsoft Bot Framework project
using CoreBot.Bots;
using CoreBot.Dialogs;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@chivandikwa
chivandikwa / ConsoleActivityHandler.cs
Created June 8, 2019 13:34
Console Bot (Microsoft Bot Framework withou aspnet core)
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
namespace ConsoleBot
{
public class ConsoleActivityHandler :
ActivityHandler
// An implementation of the IBot interface intended for further subclassing
@chivandikwa
chivandikwa / LoggingMiddleware.cs
Created June 8, 2019 21:23
Microsoft bot framework activity logging middleware
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Serilog;
namespace CoreBot.Middleware
{
public class LoggingMiddleware : IMiddleware
@chivandikwa
chivandikwa / DisabledFeaturesActionHandler.cs
Created June 12, 2019 21:56
Some custom IDisabledFeaturesHandler implementations (Microsoft.FeatureManagement and Microsoft.FeatureManagement.AspNetCore
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.FeatureManagement;
namespace FeatureManagementRecipes.Features
{
internal class DisabledFeaturesActionHandler : IDisabledFeaturesHandler
@chivandikwa
chivandikwa / RoslynDeterministic.md
Created August 28, 2019 08:55 — forked from aelij/RoslynDeterministic.md
Deterministic Builds in C#

Deterministic Builds in C#

Status

The C# compiler (Roslyn) supports deterministic builds since Visual Studio 2015. This means that compiling assemblies under the same conditions (permalink) would produce byte-for-byte equivalent binaries.

If you also intend on shipping non-portable (permalink)) PDBs, you must also make sure that paths in the PDBs are absolute using path mapping. The recommended way would be to map the enlistment (repo) root to a fixed path, such as C:\.

For more information, see this [blog post](http://blog.paranoidcoding.com/2016/04/05/deterministic-builds-in-roslyn.

@chivandikwa
chivandikwa / VerifySimpleInjectorContainerWithDiagnostics.cs
Created September 13, 2019 10:04
Verify SimpleInjector container with diagnostics
[Fact]
public void VerifyContainerWithDiagnostics()
{
Action containerVerificationAction = () => {
container.Verify(VerificationOption.VerifyAndDiagnose);
};
containerVerificationAction.Should().NotThrow();
DiagnosticResult[] res = Analyzer.Analyze(container);
@chivandikwa
chivandikwa / DelayService.cs
Last active September 16, 2019 10:14
Unit testing Task.Delay
public interface IDelayService
{
Task Delay(TimeSpan delayDuration, Action continueWith);
}
internal class DelayService : IDelayService
{
public virtual async Task Delay(TimeSpan delayDuration, Action continueWith)
{
await Task.Run(async () => { await Task.Delay(delayDuration); })
@chivandikwa
chivandikwa / Result.cs
Last active October 15, 2019 10:22
Result class for use across boundaries
public enum ResultState : byte
{
Faulted,
Success
}
public struct Result<T>
{
internal readonly ResultState State;
private readonly T _content;