This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace ThingsWhatImNotProudOf | |
{ | |
/// <summary> | |
/// Allows the manufacture and running of items within a smaller lifetime scope than the parent. | |
/// To be used sparingly when unable to inject a service within the required scope. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var tl = new Vector2(0, 0); | |
var br = new Vector2(5, 3); | |
var tr = new Vector2(5, 0); | |
var bl = new Vector2(0, 3); | |
var tlbr = new Segment(tl, br); | |
var trbl = new Segment(tr, bl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a query where the result must match or contain the given query | |
// and the subset of properties and filters. | |
descriptor.Query( | |
q => q.Bool( | |
b => b.Must( | |
mu => | |
mu.MultiMatch( | |
m => m.Fields(propertyExpressions) // Search within these properties or all. | |
.Query(searchTerm) // For this query | |
.Operator(Operator.Or))) // In any of the properties. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void RegisterDbContext<TContext>(IServiceCollection services) | |
where TContext : DbContext | |
{ | |
services.AddSingleton<SqlInstance<TContext>>(p => new SqlInstance<TContext>(builder => (TContext)ActivatorUtilities.CreateInstance<TContext>(p, builder.Options))); | |
services.AddScoped<SqlDatabase<TContext>>(p => | |
{ | |
SqlInstance<TContext> sqlInstance = p.GetRequiredService<SqlInstance<TContext>>(); | |
// Safe excecution of async via dedicated factory and unwrapping. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TypeWrapper | |
{ | |
private readonly dynamic dyn; | |
private readonly Dictionary<string, CallSite<Action<CallSite, object, object>>> setters | |
= new Dictionary<string, CallSite<Action<CallSite, object, object>>>(); | |
private readonly Dictionary<string, CallSite<Func<CallSite, object, object>>> getters | |
= new Dictionary<string, CallSite<Func<CallSite, object, object>>>(); | |
public TypeWrapper(object d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git rm -r --cached . | |
git add . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
declare -a build_projects=('./src/My.Extensions.ApiVersioning/') | |
declare -a test_projects=('./tests/IntegrationTests/' './tests/UnitTests/') | |
pwsh -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1' -projects " "${build_projects[@]}" "-tests " "${test_projects[@]}" | |
if [ $# -ne 0 ]; then | |
echo "Failed to build." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (176ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] | |
SELECT CASE | |
WHEN EXISTS ( | |
SELECT 1 | |
FROM [Customers] AS [x]) | |
THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) | |
END | |
--Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (185ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo Off | |
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'" | |
if not "%errorlevel%"=="0" goto failure | |
:success | |
ECHO successfully built project | |
REM exit 0 | |
goto end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A very simple service example contract with an event. | |
// Using an interface ensures that every implementation has same events. | |
public interface IContentService | |
{ | |
event EventHandler Saved; | |
} | |
// Our component contract | |
public interface IComponent : IDisposable | |
{ |