Skip to content

Instantly share code, notes, and snippets.

View jbogard's full-sized avatar

Jimmy Bogard jbogard

View GitHub Profile
public class MediatorPipeline<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> _inner;
private readonly IEnumearble<IMessageValidator<TRequest>> _validators;
public MediatorPipeline(IRequestHandler<TRequest, TResponse> inner,
IEnumerable<IMessageValidator<TRequest>> validators)
{
@jbogard
jbogard / Featurefolders.cs
Created October 3, 2013 15:55
Feature folders
public class FeatureViewLocationRazorViewEngine : RazorViewEngine
{
public FeatureViewLocationRazorViewEngine()
{
ViewLocationFormats = new[]
{
"~/Features/{1}/{0}.cshtml",
"~/Features/{1}/{0}.vbhtml",
"~/Features/Shared/{0}.cshtml",
"~/Features/Shared/{0}.vbhtml",
@jbogard
jbogard / UrlHelprLinkr.cs
Created December 11, 2013 21:37
Hyprlinkr + UrlHelper
using System;
using System.Linq.Expressions;
using System.Web.Http;
using System.Web.Http.Routing;
using Ploeh.Hyprlinkr;
public static class UrlHelperExtensions
{
public static Uri Link<T, TResult>(this UrlHelper helper, Expression<Func<T, TResult>> expression)
where T : ApiController
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<Source, Dest>();
});
IMapper mapper = config.CreateMapper();
var source = new Source();
var dest = mapper.Map<Source, Dest>(source);
void Main()
{
var configurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
var mapper = new MappingEngine(configurationStore);
var server = new Server();
configurationStore
.CreateMap<From, To>()
.ForMember(d => d.ServerThing, m => m.MapFrom(s => s.ServerThingId))
public class DatabaseDeleter
{
private readonly ISessionFactory _configuration;
private static readonly string[] _ignoredTables = new[] { "sysdiagrams", /* DB Migration tables too */ };
private static string[] _tablesToDelete;
private static string _deleteSql;
private static object _lockObj = new object();
private static bool _initialized;
public DatabaseDeleter(ISessionFactory sessionSource)
public class MediatorPipeline<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> _inner;
private readonly IEnumearble<IMessageValidator<TRequest>> _validators;
private readonly IMessageAuthorizer _authorizer;
public MediatorPipeline(IRequestHandler<TRequest, TResponse> inner,
IEnumerable<IMessageValidator<TRequest>> validator,
public class BetterDefaultModelBinder : DefaultModelBinder
{
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
var model = base.CreateModel(controllerContext, bindingContext, modelType);
if (model == null || model is IEnumerable)
return model;
foreach (var property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))