Skip to content

Instantly share code, notes, and snippets.

View dealproc's full-sized avatar

Richard Bennett dealproc

View GitHub Profile
@dealproc
dealproc / ServiceBase.cs
Created October 27, 2022 20:50
ServiceBase for ReactiveDomain
public class ServiceBase : IHandle<IMessage>,
IPublisher, IDisposable {
private readonly Func<IListener> _getListener;
private readonly List<IListener> _listeners = new();
private readonly InMemoryBus _bus;
private readonly QueuedHandler _queue;
private readonly List<IDisposable> _disposables = new();
public ServiceBase(string name, ISubscriber inBus, IPublisher outBus, IConfiguredConnection connection) : this(name, inBus, outBus, () => connection.GetQueuedListener(name)) {
}
@dealproc
dealproc / Converter.cs
Created May 3, 2020 01:09
System.Text.Json ValueConverter
public class ValueObjectConverter : JsonConverterFactory
{
public override bool CanConvert(Type typeToConvert)
{
if (typeToConvert.BaseType == null) return false;
if (!typeToConvert.BaseType.IsGenericType) return false;
if (typeToConvert.BaseType.GetGenericTypeDefinition() != typeof(ValueObject<>)) return false;
return true;
}
@dealproc
dealproc / DocumentConverter.cs
Created April 21, 2020 18:17
System.Text.Json parser for slip-based messaging documents
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace YourNamespace {
public class StreamServer : IDisposable
{
static Serilog.ILogger Log = Serilog.Log.ForContext<StreamServer>();
private const byte ACK = 0x06;
private const byte NAK = 0x15;
private const string HOST_TO_TERMINAL = "[Host->Terminal]";
private const string TERMINAL_TO_HOST = "[Terminal->Host]";
private const byte STX = 0x02;
private const byte ETX = 0x03;
private const string ACK_STR = "<ACK>";
@dealproc
dealproc / 1-IAccountService.cs
Created March 17, 2019 10:59
Multi-Tenant Solutions - IAccountService.cs
public interface IAccountService {
IEnumerable<AccountPmo> List();
AccountPmo Get(string guid);
AccountPmo Save(AccountPmo model);
AccountPmo Delete(string guid);
}
@dealproc
dealproc / ISessionSource.cs
Created March 17, 2019 10:38
Multi-Tenant Solutions - ISessionSource.cs
public interface ISessionSource {
ISession CreateSession();
}
@dealproc
dealproc / NHibernateMultiTenantSessionSource.cs
Last active March 17, 2019 10:40
Multi-Tenant Solutions - NHibernateMultiTenantSessionSource.cs
public class NHibernateMultiTenantSessionSource : ISessionSource {
#region Static Members and Constructor.
static readonly object _FactorySyncRoot = new object();
static readonly ConcurrentDictionary<string, ISessionFactory> _SessionFactories = new ConcurrentDictionary<string, ISessionFactory>();
#endregion
readonly IConfigurationReader _configurationManager;
readonly IAccountAccessor _accountAccessor;
readonly string _connectionStringModel;
@dealproc
dealproc / Repository<T>.cs
Created March 17, 2019 07:19
Multi-Tenant Solutions - Repository<T>.cs
public abstract class Repository<T> : IRepository<T> {
protected readonly ISessionSource _SessionSource;
public Repository(ISessionSource sessionSource) {
if (sessionSource == null) {
throw new ArgumentNullException("sessionFactory");
}
_SessionSource = sessionSource;
}
@dealproc
dealproc / IRepository<T>.cs
Created March 17, 2019 07:12
Multi-Tenant Solutions - IRepository<T>.cs
public interface IRepository<T> : IProject<T> where T : class, new() {
T Get(int id);
T GetFirst(Expression<Func<T, bool>> condition);
IEnumerable<T> GetAll();
T SaveOrUpdate(T entity);
IEnumerable<T> SaveOrUpdate(IEnumerable<T> entities);
void Delete(T item);
// other various operations on your repository of choice ...
}
@dealproc
dealproc / NHibernateMultiTenantSessionSource.cs
Last active March 17, 2019 07:11
Multi-Tenant Solutions - NHibernateMultiTenantSessionSource.cs
public class NHibernateMultiTenantSessionSource : ISessionSource {
#region Static Members and Constructor.
static readonly object _FactorySyncRoot = new object();
static readonly ConcurrentDictionary<string, ISessionFactory> _SessionFactories = new ConcurrentDictionary<string, ISessionFactory>();
#endregion
readonly IConfigurationReader _configurationManager;
readonly IAccountAccessor _accountAccessor;
readonly string _connectionStringModel;
public NHibernateMultiTenantSessionSource(IConfigurationReader configurationManager, IAccountAccessor accountAccessor) {