public void Connect(string id, Type classType, Type serviceType, ComponentLifestyle lifestyle) { Hashtable extendingProperties = new Hashtable(); extendingProperties[typeof(ComponentLifestyle)] = lifestyle; switch (lifestyle) { case ComponentLifestyle.Singleton: Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties); break; case ComponentLifestyle.Transient: Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties); break; case ComponentLifestyle.DependencyInjectionOnly: Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties); break; case ComponentLifestyle.Undefined: Kernel.AddComponent(id, serviceType, classType); break; default: throw new ArgumentException("ComponentLifestyle 参数无效: " + lifestyle); } }
public Registration( IComponentDescriptor descriptor, IComponentActivator activator, IEnumerable <IParameter> parameters, ComponentLifestyle lifestyle) { _descriptor = Enforce.ArgumentNotNull(descriptor, "descriptor"); _activator = Enforce.ArgumentNotNull(activator, "activator"); _lifestyle = lifestyle; _scope = scope.InstanceScopeFactory.ToScope(lifestyle); }
public static bool IsComponentLifestyle(this Type type, ComponentLifestyle lifestyle) { var a = type.GetCustomAttributes(typeof(ComponentAttribute), true) .OfType <ComponentAttribute>() .FirstOrDefault(); if (a == null) { return(false); } return(a.Lifestyle == lifestyle); }
public static IScope ToScope(ComponentLifestyle lifestyle) { switch (lifestyle) { case ComponentLifestyle.Transient: return(new TransientScope()); case ComponentLifestyle.Singleton: return(new SingletonScope()); default: throw new NotSupportedException(string.Format("生命周期 '{0}' 不可识别.", lifestyle)); } }
public Descriptor(string id , IEnumerable <Type> services , Type implementationType , ComponentLifestyle lifestyle , int level , IEnumerable <IParameter> parameters , IProperties extendedProperties) { _id = Enforce.ArgumentNotNullOrEmpty(id, "id"); _implementationType = Enforce.ArgumentNotNull(implementationType, "implementationType"); _services = services; _lifestyle = lifestyle; _level = level; _parameters = parameters; _extendedProperties = extendedProperties; }
public void Register(Type implementationType, ComponentLifestyle lifestyle, params Type[] asType) { var builder = _containerBuilder.RegisterType(implementationType); if (asType.Length != 0) { builder = builder.As(asType); } if (lifestyle == ComponentLifestyle.PerRequest) { builder.InstancePerLifetimeScope(); } else if (lifestyle == ComponentLifestyle.Singleton) { builder.SingleInstance(); } }
public void RegisterAs <T, TAs>(ComponentLifestyle lifestyle) where T : TAs { if (lifestyle == ComponentLifestyle.PerRequest) { _containerBuilder.RegisterType <T>().As <TAs>().InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues); } else if (lifestyle == ComponentLifestyle.Singleton) { _containerBuilder.RegisterType <T>().As <TAs>().SingleInstance().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues); } else if (lifestyle == ComponentLifestyle.Transient) { _containerBuilder.RegisterType <T>().As <TAs>().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues); } else { throw new ArgumentOutOfRangeException(nameof(lifestyle), lifestyle, null); } }
private LifestyleType GetLifestyleType(ComponentLifestyle componentLifestyle) { var lifestyleType = (LifestyleType)Enum.Parse(typeof(LifestyleType), componentLifestyle.ToString(), true); return(lifestyleType); }
public void Register <T, TAs>(ComponentLifestyle lifestyle) where T : TAs { Register(typeof(T), lifestyle, new[] { typeof(TAs) }); }
public ComponentAttribute(ComponentLifestyle lifestyle, bool start) { Lifestyle = lifestyle; Start = start; }
public ComponentAttribute(ComponentLifestyle lifestyle) : this(lifestyle, false) { }
public ComponentAttribute(ComponentLifestyle lifestyle = ComponentLifestyle.Transient) { _lifestyle = lifestyle; }
public void Connect(string id, IEnumerable <Type> serviceTypes, Type classType, ComponentLifestyle lifestyle, IEnumerable <IParameter> parameters, IProperties properties) { throw new NotImplementedException(); }
public void Connect(string id, Type classType, Type serviceType, ComponentLifestyle lifestyle) { _adapter.Connect(id, classType, serviceType, lifestyle); }
public void Register <T>(ComponentLifestyle lifestyle) { Register(typeof(T), lifestyle); }
void IContainer.RegisterComponent(string key, Type serviceType, Type classType, ComponentLifestyle componentLifestyle) { LifestyleType lifestyleType = GetLifestyleType(componentLifestyle); _container.AddComponentLifeStyle(key, serviceType, classType, lifestyleType); }
public ComponentAttribute(ComponentLifestyle lifestyle) { Lifestyle = lifestyle; }
public void Register(Type implementationType, ComponentLifestyle lifestyle) { Register(implementationType, lifestyle, new Type[] { }); }
public void RegisterAs <T, TAs>(ComponentLifestyle lifestyle) where T : TAs { _dependencyContainer.RegisterAs <T, TAs>(lifestyle); }
public virtual TSyntax WithLifestyle(ComponentLifestyle lifestyle) { _lifestyle = lifestyle; return(Syntax); }
public void Register(Type implementationType, ComponentLifestyle lifestyle, params Type[] asType) { _dependencyContainer.Register(implementationType, lifestyle, asType); RegisteredInterfaces.AddRange(asType); }