private static void RegisterDefaultInstance <T, TDefault>(this ContainerBuilder builder, Registration <T> registration, string name = null) where T : class where TDefault : class, T, new() { if (registration != null) { builder.Register(registration, name); } else { if (name == null) { builder.RegisterInstance(new TDefault()).As <T>(); } else { builder.RegisterInstance(new TDefault()).Named <T>(name); } } }
private static void RegisterDecorator <T, TDecorator>(this ContainerBuilder builder, Registration <T> registration) where T : class where TDecorator : T { builder.Register(registration, DecoratorRegistrationName); builder.RegisterType <TDecorator>(); builder.Register <T>(ctx => { var inner = Autofac.Core.ResolvedParameter.ForNamed <T>(DecoratorRegistrationName); return(ctx.Resolve <TDecorator>(inner)); }); }
private static void RegisterDefaultType <T, TDefault>(this ContainerBuilder builder, Registration <T> registration, string name = null) where T : class where TDefault : T { if (registration != null) { builder.Register(registration, name); } else { if (name == null) { builder.RegisterType <TDefault>().As <T>(); } else { builder.RegisterType <TDefault>().Named <T>(name); } } }
private static void RegisterDecoratorDefaultType <T, TDecorator, TDefault>(this ContainerBuilder builder, Registration <T> registration) where T : class where TDecorator : T where TDefault : class, T, new() { builder.RegisterDefaultType <T, TDefault>(registration, DecoratorRegistrationName); builder.RegisterDecorator <T, TDecorator>(DecoratorRegistrationName); }