public static Autofac.Builder.IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> PerLifeStyle <TLimit, TActivatorData, TRegistrationStyle>(this Autofac.Builder.IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> builder, ComponentLifeStyle lifeStyle) { switch (lifeStyle) { case ComponentLifeStyle.LifetimeScope: //return HttpContext.Current != null ? builder.InstancePerHttpRequest() : builder.InstancePerLifetimeScope(); case ComponentLifeStyle.Transient: return(builder.InstancePerDependency()); case ComponentLifeStyle.Singleton: return(builder.SingleInstance()); default: return(builder.SingleInstance()); } }
private void ApplyLifeTime <T>(Autofac.Builder.IRegistrationBuilder <T, Autofac.Builder.IConcreteActivatorData, Autofac.Builder.SingleRegistrationStyle> x, LifeSpan lifeSpan) { switch (lifeSpan) { case LifeSpan.InstancePerLifetimeScope: x.InstancePerLifetimeScope(); break; case LifeSpan.NewInstancePerRequest: x.InstancePerRequest(); break; case LifeSpan.SingleInstance: x.SingleInstance(); break; } }