public static void Main()
c.Register<IActionHandler, SomeActionHandler>();
c.Register<IAsyncRequestHandler<string, string>, SomeRequestHandler>();
c.Register<DbContext, Model1>(reuse: Reuse.InResolutionScopeOf(typeof(IAsyncRequestHandler<,>)));
c.Register(typeof(IAsyncRequestHandler<,>), typeof(Decorator<,>), setup: Setup.Decorator);
var d = (Decorator<string, string>)c.Resolve<IAsyncRequestHandler<string, string>>();
Console.WriteLine("decorator: " + d);
Console.WriteLine("decorator DbContext is nut null: " + (d.DbContext != null));
Console.WriteLine("decorator DbContext is the same as decorated: " + (d.DbContext == d.DecoratedDbContext));
Console.WriteLine("decorator DbContext is the same as decorator action handler's: " + (d.DbContext == d.ActionHandler.DbContext));
public interface IAsyncRequestHandler<TRequest, TResponse>
DbContext DbContext { get; }
public interface IActionHandler
DbContext DbContext { get; }
public class DbContext {}
public class Model1 : DbContext {}
public class Decorator<TRequest, TResponse> : IAsyncRequestHandler<TRequest, TResponse>
public DbContext DbContext { get; set; }
public DbContext DecoratedDbContext { get { return _decorated.DbContext; } }
IAsyncRequestHandler<TRequest, TResponse> _decorated;
public readonly IActionHandler ActionHandler;
public Decorator(DbContext dbContext, IActionHandler handler, IAsyncRequestHandler<TRequest, TResponse> inner)
public class SomeRequestHandler : IAsyncRequestHandler<string, string>
public DbContext DbContext { get; private set; }
public SomeRequestHandler(DbContext dbContext)
public class SomeActionHandler : IActionHandler
public DbContext DbContext { get; private set; }
public SomeActionHandler(DbContext context)