Skip to content

Instantly share code, notes, and snippets.

View merken's full-sized avatar

Maarten Merken merken

View GitHub Profile
public static class ServiceCollectionExtensions
{
public static void RegisterAllTypes<T>(this IServiceCollection services, Assembly[] assemblies,
ServiceLifetime lifetime = ServiceLifetime.Transient)
{
var typesFromAssemblies = assemblies.SelectMany(a => a.DefinedTypes.Where(x => x.GetInterfaces().Contains(typeof(T))));
foreach (var type in typesFromAssemblies)
services.Add(new ServiceDescriptor(typeof(T), type, lifetime));
}
}
@merken
merken / SchemaInterceptor.cs
Last active January 20, 2022 16:43
SchemaInterceptor
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace efcore_tenancy.Infrastructure
{
public class SchemaInterceptor : DbCommandInterceptor
{
private readonly TenantInfo tenantInfo;
module.exports = function dataCyLoader(source) {
var dataAttr= 'data-cy=\"([^"]*)\"';
if(source.match(dataAttr)){
source = source.replace(new RegExp(dataAttr, 'g'), '');
}
return source;
}
@merken
merken / Console.csproj
Created April 2, 2021 20:51
Console csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
@merken
merken / Program.1.cs
Created April 2, 2021 20:46
Initial hello world
using System;
namespace ConsoleToWeb
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!"); // => This needs to be converted into a web app
}
@merken
merken / Program.cs
Last active March 30, 2021 12:35
FooService
using System;
using FuncR;
using Microsoft.Extensions.DependencyInjection;
namespace Your.First.Function
{
// We don't need no, implementation
public interface IFooService
{
string Foo(int numberOfFoos);
@merken
merken / MyDbContext.cs
Last active March 8, 2021 13:46
Providing a connection string in EF core
public class MyDbContext : MyContext
{
private readonly string connectionString;
public MyDbContext(string connectionString) : base()
{
this.connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@merken
merken / LoggerProxy.cs
Created March 30, 2020 15:14
LoggerProxy.cs
using System;
using System.Reflection;
namespace MyApp
{
public class LoggerProxy : DispatchProxy
{
private object remote;
public LoggerProxy SetRemoteObject(object remote)
{
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace TableStoragePlugin
{
using System;
using System.Data;
using System.Data.Common;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Prise.Plugin;
namespace TableStoragePlugin
{
[PluginBootstrapper(PluginType = typeof(TableStorageProductsRepository))]