private static ComponentRegistration <T> SetLifeStyle <T>(LifeStyleType lifeStyle, ComponentRegistration <T> registration) where T : class { if (lifeStyle == LifeStyleType.Singleton) { return(registration.LifestyleSingleton()); } else if (lifeStyle == LifeStyleType.Transient) { return(registration.LifestyleTransient()); } else if (lifeStyle == LifeStyleType.PerWebRequest) { return(registration.LifestylePerWebRequest()); } else if (lifeStyle == LifeStyleType.PerThread) { return(registration.LifestylePerThread()); } else if (lifeStyle == LifeStyleType.Scoped) { return(registration.LifestyleScoped()); } return(registration); }
/// <summary> /// Uses an instance lifestyle where the instance is bound to (and thus will re-used across) the current Rebus transaction context /// </summary> public static ComponentRegistration <TService> LifestylePerRebusMessage <TService>(this ComponentRegistration <TService> registration) where TService : class { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } return(registration.LifestyleScoped <RebusScopeAccessor>()); }
private void RegisterWindsor(Microsoft.Extensions.DependencyInjection.ServiceDescriptor item) { try { ComponentRegistration <object> r = null; if (item.ImplementationType != null) { if (_container.Kernel.HasComponent(item.ImplementationType)) { return; } r = Component.For(item.ServiceType).ImplementedBy(item.ImplementationType); } else if (item.ImplementationFactory != null) { var provider = WindsorRegistrationHelper.CreateServiceProvider(_container, this); r = Component.For(item.ServiceType).UsingFactoryMethod(() => item.ImplementationFactory.Invoke(provider)); } else if (item.ImplementationInstance != null) { r = Component.For(item.ServiceType).UsingFactoryMethod(() => item.ImplementationInstance); } if (item.Lifetime == ServiceLifetime.Scoped) { _container.Register(r.LifestyleScoped()); } else if (item.Lifetime == ServiceLifetime.Transient) { _container.Register(r.LifestyleTransient()); } else if (item.Lifetime == ServiceLifetime.Singleton) { _container.Register(r.LifestyleSingleton()); } } catch (Exception ex) { if (!ex.Message.Contains("Component Microsoft.Extensions.Options.OptionsManager`1 could not be registered") && !ex.Message.Contains("Component Late bound Microsoft.Extensions.Options.IConfigureOptions`1[[Microsoft.Extensions.Logging.LoggerFilterOptions, Microsoft.Extensions.Logging")) { // Known issue at: https://gist.github.com/cwe1ss/050a531e2711f5b62ab0 throw; } } }
private static ComponentRegistration <T> ApplyLifestyle <T>(ComponentRegistration <T> registration, DependencyLifeStyle lifeStyle) where T : class { switch (lifeStyle) { case DependencyLifeStyle.Transient: return(registration.LifestyleTransient()); case DependencyLifeStyle.Singleton: return(registration.LifestyleSingleton()); case DependencyLifeStyle.Scoped: return(registration.LifestyleScoped()); default: return(registration); } }
/// <summary> /// Lifestyle conversion and application /// </summary> public static ComponentRegistration <T> ApplyLifestyle <T>(this ComponentRegistration <T> registration, DependencyLifeStyle lifeStyle) where T : class { switch (lifeStyle) { case DependencyLifeStyle.Transient: return(registration.LifestyleTransient()); case DependencyLifeStyle.Scoped: return(registration.LifestyleScoped <LocalLifetimeScopeAccessor>()); case DependencyLifeStyle.Singleton: return(registration.LifestyleSingleton()); default: throw new ArgumentException(nameof(lifeStyle)); } }
public static ComponentRegistration <T> WithLifetime <T>(this ComponentRegistration <T> registration, Lifetime lifetime) where T : class { switch (lifetime) { case Lifetime.Transient: return(registration.LifestyleTransient()); case Lifetime.Scope: return(registration.LifestyleScoped()); case Lifetime.Singleton: return(registration.LifestyleSingleton()); default: throw new NotSupportedException(lifetime.ToString()); } }
ComponentRegistration <T> Lifestyle <T>(ComponentRegistration <T> registration, FeignClientLifetime lifetime) where T : class { switch (lifetime) { case FeignClientLifetime.Transient: return(registration.LifestyleTransient()); case FeignClientLifetime.Singleton: return(registration.LifestyleSingleton()); case FeignClientLifetime.Scoped: return(registration.LifestyleScoped()); default: return(registration); } }
/// <summary> /// Set the lifestyle of the registered builder /// </summary> private ComponentRegistration <T> ApplyLifestyle <T>(ComponentRegistration <T> registration, DependencyLifeStyle lifeStyle) where T : class { switch (lifeStyle) { case DependencyLifeStyle.Transient: return(registration.LifestyleTransient()); case DependencyLifeStyle.Scoped: return(registration.LifestyleScoped()); case DependencyLifeStyle.Singleton: return(registration.LifestyleSingleton()); default: throw new ArgumentException(nameof(lifeStyle)); } }
private static ComponentRegistration <object> ConfigureLifecycle( this ComponentRegistration <object> registrationBuilder, ServiceLifetime serviceLifetime) { switch (serviceLifetime) { case ServiceLifetime.Singleton: registrationBuilder.LifestyleSingleton(); break; case ServiceLifetime.Scoped: registrationBuilder.LifestyleScoped(); break; case ServiceLifetime.Transient: registrationBuilder.LifestyleTransient(); break; } return(registrationBuilder); }
internal static ComponentRegistration <T> ApplyLifestyle <T>(this ComponentRegistration <T> registration, LifetimeType lifetimeType, bool classicWeb = false) where T : class { switch (lifetimeType) { case LifetimeType.Transient: return(registration.LifestyleTransient()); //return registration.LifestyleCustom<MsScopedTransientLifestyleManager>(); case LifetimeType.Singleton: return(registration.LifestyleSingleton()); //return registration.LifestyleCustom<MsScopedLifestyleManager>(); case LifetimeType.Scoped: //return classicWeb ? registration.LifestylePerWebRequest() : registration.LifestyleCustom<MyScopedSingletonLifestyleManager>(); //registration.LifestyleScoped();//// return(classicWeb ? registration.LifestylePerWebRequest() : registration.LifestyleScoped()); //// default: return(registration); } }
public static ComponentRegistration <TService> LifestylePerSession <TService>(this ComponentRegistration <TService> reg) where TService : class { return(reg.LifestyleScoped <WebSessionScopeAccessor>()); }
/// <summary> /// Uses an instance lifestyle where the instance is bound to (and thus will re-used across) the current Rebus transaction context /// </summary> public static ComponentRegistration <TService> LifestylePerRebusMessage <TService>(this ComponentRegistration <TService> registration) where TService : class { return(registration.LifestyleScoped <RebusScopeAccessor>()); }
protected override ComponentRegistration <T> PerUnitOfWorkLifeStyleRegistration <T>(ComponentRegistration <T> registration) { //LifestyleScoped means you get the same object within the scope of the container (which you create by calling container.BeginScope()) return(registration.LifestyleScoped()); }