Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dcomartin's full-sized avatar

Derek Comartin dcomartin

View GitHub Profile
@dcomartin
dcomartin / gist:82a81fa4f5a217c50702
Last active August 29, 2015 14:19
Unity Container with MediatR
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<IRepository>(new InjectionFactory(context => new EventStoreRepository(context.Resolve<IStoreEvents>(), new AggregateFactory(), new ConflictDetector())));
container.RegisterType<IMediator>(new InjectionFactory(x => new Mediator(() => new UnityServiceLocator(x))));
container.RegisterTypes(AllClasses.FromAssemblies(typeof(Commands.InventoryCommandHandler).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager);
container.RegisterTypes(AllClasses.FromAssemblies(typeof(Queries.InventoryQueryHandler).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager);
container.RegisterType<IStoreEvents>(new InjectionFactory(context => Wireup.Init()
.UsingSqlPersistence("EventStore")
.WithDialect(new MySqlDialect())
.EnlistInAmbientTransaction()
@dcomartin
dcomartin / gist:5e2aae81a5154507fc98
Last active August 29, 2015 14:19
Unity RegisterType IMediator
container.RegisterType<IMediator>(new InjectionFactory(x => new Mediator(() => new UnityServiceLocator(x))));
@dcomartin
dcomartin / gist:715f97d5765fac8e426a
Created April 23, 2015 02:37
Mediator Constructor
public Mediator(ServiceLocatorProvider serviceLocatorProvider);
@dcomartin
dcomartin / gist:12fe98b3cd40d332c5ff
Last active August 29, 2015 14:20
Demo-AsyncException
using System;
using System.Threading.Tasks;
namespace dcomartin.Demo.AsyncAwaitExceptions
{
class Program
{
static void Main(string[] args)
{
// Since main entry does not support async, lets create a async task.
Add("sendErrorEmails", true);
Add("errorEmail", "derek@codeopinion.com");
var sendErrorEmails = Config.Global.Get<bool>("sendErrorEmails");
var errorEmail = Config.Global.Get<string>("errorEmail");
// Load from file system
Config.Global.LoadScriptFile("path/to/MyConfig.csx");
// Load from web
Config.Global.LoadWebScript(new Uri("https://www.domain.com/MyConfig.csx"));
@dcomartin
dcomartin / gist:0d2d3e72eabe863987af
Created May 26, 2015 01:48
ConfigR Complex Type
namespace AnotherProject
{
public class ErrorConfig
{
public bool SendEmails { get; set; }
public string Email { get; set; }
}
}
#r bin/AnotherProject.dll
using AnotherProject;
Add("error", new ErrorConfig { SendEmails = true, Email = "derek@codeopinion.com" });
Add("sendErrorEmails", true);
Add("errorEmail", "derek@codeopinion.com");
@dcomartin
dcomartin / gist:9ead866d4460e024cb18
Created May 26, 2015 01:50
ConfigR Get Complex Type
var errorConfig = Config.Global.Get<ErrorConfig>("error");