using System.Diagnostics;
using SimpleInjector.Diagnostics;
using SimpleInjector.Lifestyles;
namespace ConsoleAppTestSimpleInjector
public static class Program
static readonly Container Container;
Container = new Container();
Container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
Container.Options.EnableAutoVerification = false;
Container.Register<ITarget, Target>(Lifestyle.Scoped);
Container.RegisterDecorator(typeof(ITarget), typeof(InstrumentationTargetDecorator), Lifestyle.Scoped);
Container.RegisterDecorator(typeof(ITarget), typeof(ResilienceTargetDecorator), Lifestyle.Scoped);
Container.RegisterDecorator(typeof(ITarget), typeof(InstrumentationTargetDecorator), Lifestyle.Scoped);
public static void Main(string[] args)
using (AsyncScopedLifestyle.BeginScope(Container))
var service = Container.GetInstance<ITarget>();
public class Target : ITarget
Console.WriteLine(GetType().Name + " called.");
public class ResilienceTargetDecorator : ITarget
private readonly ITarget _target;
public ResilienceTargetDecorator(ITarget target)
Console.WriteLine(GetType().Name + " called.");
public class InstrumentationTargetDecorator : ITarget
private readonly ITarget _target;
public InstrumentationTargetDecorator(ITarget target)
var timer = new Stopwatch();
Console.WriteLine(_target.GetType().Name + " took " + timer.ElapsedMilliseconds + " ms.");