void Common.IContainer.Configure(Type component, DependencyLifecycle dependencyLifecycle) { lock (configuredInstances) { if(configuredInstances.ContainsKey(component)) return; } var lifecycle = GetLifecycleFrom(dependencyLifecycle); ConfiguredInstance configuredInstance = null; container.Configure(x => { configuredInstance = x.For(component) .LifecycleIs(lifecycle) .Use(component); x.EnableSetterInjectionFor(component); foreach (var implementedInterface in GetAllInterfacesImplementedBy(component)) { x.RegisterAdditionalInterfaceForPluginType(implementedInterface, component,lifecycle); x.EnableSetterInjectionFor(implementedInterface); } }); lock (configuredInstances) configuredInstances.Add(component, configuredInstance); }
public void Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { ConfigureComponentAdapter config = container.ResolveAll<ConfigureComponentAdapter>().Where(x => x.ConfiguredType == concreteComponent). FirstOrDefault(); if (config == null) { IEnumerable<Type> interfaces = GetAllServiceTypesFor(concreteComponent); config = new ConfigureComponentAdapter(container, concreteComponent); container.RegisterInstance(Guid.NewGuid().ToString(), config); foreach (Type t in interfaces) { if (typesWithDefaultInstances.Contains(t)) { container.RegisterType(t, concreteComponent, Guid.NewGuid().ToString(), GetLifetimeManager(dependencyLifecycle)); } else { container.RegisterType(t, concreteComponent, GetLifetimeManager(dependencyLifecycle)); typesWithDefaultInstances.Add(t); } } } }
void Common.IContainer.Configure(Type component, DependencyLifecycle dependencyLifecycle) { var registration = this.GetComponentRegistration(component); if (registration != null) return; var builder = new ContainerBuilder(); var services = component.GetAllServices().ToArray(); var registrationBuilder = builder.RegisterType(component).As(services).PropertiesAutowired(); SetLifetimeScope(dependencyLifecycle, registrationBuilder); builder.Update(this.container.ComponentRegistry); }
protected virtual void ConfigureLifetimeScope <T>(DependencyLifecycle dependencyLifecycle, IRegistrationBuilder <T, ConcreteReflectionActivatorData, SingleRegistrationStyle> registration) { switch (dependencyLifecycle) { case DependencyLifecycle.SingleInstance: registration.SingleInstance(); break; case DependencyLifecycle.InstancePerDependency: registration.InstancePerDependency(); break; case DependencyLifecycle.InstancePerUnitOfWork: registration.InstancePerLifetimeScope(); break; default: throw new ArgumentException("Unknown container lifecycle - " + dependencyLifecycle); } }
static void SetLifetimeScope(DependencyLifecycle dependencyLifecycle, IRegistrationBuilder <object, IConcreteActivatorData, SingleRegistrationStyle> registrationBuilder) { switch (dependencyLifecycle) { case DependencyLifecycle.InstancePerCall: registrationBuilder.InstancePerDependency(); break; case DependencyLifecycle.SingleInstance: registrationBuilder.SingleInstance(); break; case DependencyLifecycle.InstancePerUnitOfWork: registrationBuilder.InstancePerLifetimeScope(); break; default: throw new ArgumentException("Unhandled lifecycle - " + dependencyLifecycle); } }
public void Bind(Type service, Type typeTo, DependencyLifecycle dependencyLifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(typeTo, nameof(typeTo)); ITypeCallbackConstructorObjectPriorityUseWithSyntax syntax = _injector.BindWithManualBuild(service).To(typeTo).InScope(GetScope(dependencyLifecycle)); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) { syntax.WithParameter(ConvertParameter(parameters[index], true)); } } if (name != null) { syntax.NamedBinding(name); } syntax.Build(); }
public void Configure <T>(Func <T> componentFactory, DependencyLifecycle dependencyLifecycle) { var funcType = typeof(T); var registration = GetRegistrationFromDependencyLifecycle(dependencyLifecycle, funcType, () => componentFactory()); foreach (var implementedInterface in funcType.GetInterfaces()) { if (HasComponent(implementedInterface)) { var existingRegistration = GetExistingCollectionRegistrationsFor(implementedInterface); RegisterCollection(implementedInterface, existingRegistration.Union(new[] { registration })); } else { container.AddRegistration(implementedInterface, registration); } } container.AddRegistration(funcType, registration); }
public void Configure(Type component, DependencyLifecycle dependencyLifecycle) { lock (configuredInstances) { if (configuredInstances.ContainsKey(component)) { return; } } var lifecycle = GetLifecycleFrom(dependencyLifecycle); ConfiguredInstance configuredInstance = null; container.Configure(x => { configuredInstance = x.For(component) .LifecycleIs(lifecycle) .Use(component); x.EnableSetterInjectionFor(component); var interfaces = GetAllInterfacesImplementedBy(component).ToList(); foreach (var implementedInterface in interfaces) { x.For(implementedInterface) .LifecycleIs(lifecycle) .Use(c => c.GetInstance(component)); x.EnableSetterInjectionFor(implementedInterface); } }); lock (configuredInstances) { configuredInstances.Add(component, configuredInstance); } }
public void Bind(Type service, Type typeTo, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(typeTo, nameof(typeTo)); IBindingWhenInNamedWithOrOnSyntax <object> syntax = _kernel .Bind(service) .To(typeTo); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) { syntax.WithParameter(ConvertParameter(parameters[index], true)); } } SetLifecycle(syntax, lifecycle); if (name != null) { syntax.Named(name); } }
public void Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { if (HasComponent(concreteComponent)) { return; } var interfaces = GetAllServiceTypesFor(concreteComponent); foreach (Type t in interfaces) { if (DefaultInstances.Contains(t)) { container.RegisterType(t, concreteComponent, Guid.NewGuid().ToString(), GetLifetimeManager(dependencyLifecycle)); } else { container.RegisterType(t, concreteComponent, GetLifetimeManager(dependencyLifecycle)); DefaultInstances.Add(t); } } }
public void Configure(Type component, DependencyLifecycle dependencyLifecycle) { if (isBuilt) { container = container.Clone(); } var registration = GetRegistrationFromDependencyLifecycle(dependencyLifecycle, component); foreach (var implementedInterface in component.GetInterfaces()) { if (HasComponent(implementedInterface)) { var existingRegistration = GetExistingCollectionRegistrationsFor(implementedInterface); RegisterCollection(implementedInterface, existingRegistration.Union(new[] { registration })); } else { container.AddRegistration(implementedInterface, registration); } } if (HasComponent(component)) { var existingRegistration = GetExistingRegistrationsFor(component); var first = existingRegistration.First(); if (!AreRegistrationsEqual(first, registration)) { container.Collection.Register(component, existingRegistration.Union(new[] { registration })); } } else { container.AddRegistration(component, registration); } }
public void Configure <T>(Func <T> componentFactory, DependencyLifecycle dependencyLifecycle) { var pluginType = typeof(T); lock (configuredInstances) { if (configuredInstances.ContainsKey(pluginType)) { return; } } var lifecycle = GetLifecycleFrom(dependencyLifecycle); LambdaInstance <T, T> lambdaInstance = null; container.Configure(x => { lambdaInstance = x.For <T>() .LifecycleIs(lifecycle) .Use("Custom constructor func", componentFactory); x.EnableSetterInjectionFor(pluginType); foreach (var implementedInterface in GetAllInterfacesImplementedBy(pluginType)) { x.For(implementedInterface).Use(c => c.GetInstance <T>()); x.EnableSetterInjectionFor(implementedInterface); } } ); lock (configuredInstances) { configuredInstances.Add(pluginType, lambdaInstance); } }
/// <summary> /// Sets the lifecycle. /// </summary> protected virtual void SetLifecycle(IBindingInSyntax<object> syntax, DependencyLifecycle lifecycle) { if (lifecycle == DependencyLifecycle.SingleInstance) { syntax.InSingletonScope(); return; } if (lifecycle == DependencyLifecycle.TransientInstance) { syntax.InTransientScope(); return; } Should.MethodBeSupported(false, "SetLifecycle(IBindingInSyntax<object> syntax, DependencyLifecycle lifecycle)"); }
void IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { typeHandleLookup[concreteComponent] = dependencyLifecycle; lock (componentProperties) if (!componentProperties.ContainsKey(concreteComponent)) componentProperties[concreteComponent] = new ComponentConfig(); }
public void Bind(Type service, Type typeTo, DependencyLifecycle dependencyLifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(typeTo, nameof(typeTo)); ITypeCallbackConstructorObjectPriorityUseWithSyntax syntax = _injector.BindWithManualBuild(service).To(typeTo).InScope(GetScope(dependencyLifecycle)); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) syntax.WithParameter(ConvertParameter(parameters[index], true)); } if (name != null) syntax.NamedBinding(name); syntax.Build(); }
protected virtual IScopeLifecycle GetScope(DependencyLifecycle lifecycle) { if (lifecycle == DependencyLifecycle.SingleInstance) return new SingletonScopeLifecycle(); if (lifecycle == DependencyLifecycle.TransientInstance) return new TransientScopeLifecycle(); Should.MethodBeSupported(false, "GetScope(DependencyLifecycle lifecycle)"); return null; }
private static void SetLifetimeScope(DependencyLifecycle dependencyLifecycle, IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder) { switch (dependencyLifecycle) { case DependencyLifecycle.InstancePerCall: registrationBuilder.InstancePerDependency(); break; case DependencyLifecycle.SingleInstance: registrationBuilder.SingleInstance(); break; case DependencyLifecycle.InstancePerUnitOfWork: registrationBuilder.InstancePerLifetimeScope(); break; default: throw new ArgumentException("Unhandled lifecycle - " + dependencyLifecycle); } }
void IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { var registrations = container.Kernel.GetAssignableHandlers(concreteComponent).Select(x=>x.ComponentModel); if (registrations.Any()) { Logger.Info("Component " + concreteComponent.FullName + " was already registered in the container."); return; } var lifestyle = GetLifestyleTypeFrom(dependencyLifecycle); var services = GetAllServiceTypesFor(concreteComponent); container.Register(Component.For(services).ImplementedBy(concreteComponent).LifeStyle.Is(lifestyle)); }
public BindingRegistration(MugenContainer container, Func <IIocContainer, IList <IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, IIocParameter[] parameters) { _container = container; _methodBindingDelegate = methodBindingDelegate; _lifecycle = lifecycle; _parameters = parameters; }
private static LifetimeManager GetLifetimeManager(DependencyLifecycle dependencyLifecycle) { switch (dependencyLifecycle) { case DependencyLifecycle.InstancePerCall: return new TransientLifetimeManager(); case DependencyLifecycle.SingleInstance: return new ContainerControlledLifetimeManager(); case DependencyLifecycle.InstancePerUnitOfWork: return new TransientLifetimeManager(); } throw new ArgumentException("Unhandled lifecycle - " + dependencyLifecycle); }
IComponentConfig <T> IConfigureComponents.ConfigureComponent <T>(Func <T> componentFactory, DependencyLifecycle instanceLifecycle) { Container.Configure(componentFactory, instanceLifecycle); return(new ComponentConfig <T>(Container)); }
IComponentConfig IConfigureComponents.ConfigureComponent(Type concreteComponent, DependencyLifecycle instanceLifecycle) { Container.Configure(concreteComponent, instanceLifecycle); return(new ComponentConfig(concreteComponent, Container)); }
/// <summary> /// Indicates that the service should be bound to the specified type. /// </summary> /// <param name="service">The specified service type.</param> /// <param name="typeTo">The specified to type</param> /// <param name="name">The specified binding name.</param> /// <param name="dependencyLifecycle"> /// The specified <see cref="DependencyLifecycle" /> /// </param> public void Bind(Type service, Type typeTo, DependencyLifecycle dependencyLifecycle, string name = null) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(typeTo, "typeTo"); var builder = new ContainerBuilder(); IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> syntax = name == null ? builder.RegisterType(typeTo).As(service) : builder.RegisterType(typeTo).Named(name, service); SetLifetimeScope(dependencyLifecycle, syntax.RegistrationData); builder.Update(_container.ComponentRegistry); }
public void BindToMethod(Type service, Func<IIocContainer, IList<IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null) { if (_isMixed && _parentInitialized) { if (!IsContainerDisposed(_parentContainer)) _parentContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); _iocContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); } else IocContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); }
/// <summary> /// Indicates that the service should be bound to the specified type. /// </summary> /// <param name="service">The specified service type.</param> /// <param name="typeTo">The specified to type</param> /// <param name="lifecycle"> /// The specified <see cref="DependencyLifecycle" /> /// </param> /// <param name="name">The specified binding name.</param> public void Bind(Type service, Type typeTo, DependencyLifecycle lifecycle, string name = null) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(typeTo, "typeTo"); IBindingWhenInNamedWithOrOnSyntax<object> syntax = _kernel .Bind(service) .To(typeTo); SetLifecycle(syntax, lifecycle); if (name != null) syntax.Named(name); }
public void Configure <T>(Func <T> component, DependencyLifecycle dependencyLifecycle) { throw new InvalidOperationException(); }
/// <summary> /// Indicates that the service should be bound to the specified type. /// </summary> /// <param name="service">The specified service type.</param> /// <param name="typeTo">The specified to type</param> /// <param name="name">The specified binding name.</param> /// <param name="dependencyLifecycle"> /// The specified <see cref="DependencyLifecycle" /> /// </param> public void Bind(Type service, Type typeTo, DependencyLifecycle dependencyLifecycle, string name = null) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(typeTo, "typeTo"); ITypeCallbackConstructorObjectPriorityUseWithSyntax syntax = _injector .BindWithManualBuild(service) .To(typeTo) .InScope(GetScope(dependencyLifecycle)); if (name != null) syntax.NamedBinding(name); syntax.Build(); }
private static void RegisterTypes(IContainerBuilder containerBuilder, IEnumerable<Type> types, DependencyLifecycle dependencyLifecycle) { foreach (var type in types) { containerBuilder.RegisterType(type, dependencyLifecycle); } }
private static LifestyleType GetLifestyleTypeFrom(DependencyLifecycle dependencyLifecycle) { switch (dependencyLifecycle) { case DependencyLifecycle.InstancePerCall: return LifestyleType.Transient; case DependencyLifecycle.SingleInstance: return LifestyleType.Singleton; case DependencyLifecycle.InstancePerUnitOfWork: return LifestyleType.Scoped; } throw new ArgumentException("Unhandled lifecycle - " + dependencyLifecycle); }
/// <summary> /// Configures the call model of the given component type. /// </summary> /// <param name="component">Type to be configured</param> /// <param name="dependencyLifecycle">The desired lifecycle for this type</param> public void Configure(Type component, DependencyLifecycle dependencyLifecycle) { if (this.HasComponent(component)) { return; } var instanceScope = this.GetInstanceScopeFrom(dependencyLifecycle); this.BindComponentToItself(component, instanceScope); this.BindAliasesOfComponentToComponent(component, instanceScope); this.propertyHeuristic.RegisteredTypes.Add(component); }
public void BindToMethod(Type service, Func <IIocContainer, IList <IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null) { if (_isMixed && _parentInitialized) { if (!IsContainerDisposed(_parentContainer)) { _parentContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); } _iocContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); } else { IocContainer.BindToMethod(service, methodBindingDelegate, lifecycle, name); } }
public void Bind(Type service, Type typeTo, DependencyLifecycle lifecycle, string name = null) { if (_isMixed && _parentInitialized) { if (!IsContainerDisposed(_parentContainer)) _parentContainer.Bind(service, typeTo, lifecycle, name); _iocContainer.Bind(service, typeTo, lifecycle, name); } else IocContainer.Bind(service, typeTo, lifecycle, name); }
IComponentConfig <T> IConfigureComponents.ConfigureComponent <T>(DependencyLifecycle instanceLifecycle) { Container.Configure(typeof(T), instanceLifecycle); return(new ComponentConfig <T>(Container)); }
public void Configure <T>(Func <T> component, DependencyLifecycle dependencyLifecycle) { }
IComponentConfig <T> IConfigureComponents.ConfigureComponent <T>(Func <IBuilder, T> componentFactory, DependencyLifecycle instanceLifecycle) { Container.Configure(() => componentFactory(this), instanceLifecycle); return(new ComponentConfig <T>(Container)); }
void IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { if (initialized) throw new InvalidOperationException("You can't alter the registrations after the container components has been resolved from the container"); typeHandleLookup[concreteComponent] = dependencyLifecycle; lock (componentProperties) if (!componentProperties.ContainsKey(concreteComponent)) componentProperties[concreteComponent] = new ComponentConfig(); }
/// <summary> /// Configures the call model of the given component type. /// </summary> /// <param name="component">Type to be configured</param> /// <param name="dependencyLifecycle">The desired lifecycle for this type</param> public void Configure(Type component, DependencyLifecycle dependencyLifecycle) { if (this.HasComponent(component)) { return; } var instanceScope = this.GetInstanceScopeFrom(dependencyLifecycle); var bindingConfigurations = this.BindComponentToItself(component, instanceScope, dependencyLifecycle == DependencyLifecycle.InstancePerUnitOfWork); this.AddAliasesOfComponentToBindingConfigurations(component, bindingConfigurations); this.propertyHeuristic.RegisteredTypes.Add(component); }
public void Configure <T>(Func <T> component, DependencyLifecycle dependencyLifecycle) { ThrowIfLocked(); builder.Configure(component, dependencyLifecycle); }
public void Bind(Type service, Type typeTo, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(typeTo, "typeTo"); IBindingWhenInNamedWithOrOnSyntax<object> syntax = _kernel .Bind(service) .To(typeTo); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) syntax.WithParameter(ConvertParameter(parameters[index], true)); } SetLifecycle(syntax, lifecycle); if (name != null) syntax.Named(name); }
public static IComponentConfig Component(Type type, DependencyLifecycle lifecycle) { throw new NotImplementedException(); }
public void BindToMethod(Type service, Func <IIocContainer, IList <IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(methodBindingDelegate, nameof(methodBindingDelegate)); if (parameters == null) { parameters = Empty.Array <IIocParameter>(); } var builder = new ContainerBuilder(); var syntax = name == null ? builder.Register((context, args) => methodBindingDelegate(this, GetParameters(parameters, args))).As(service) : builder.Register((context, args) => methodBindingDelegate(this, GetParameters(parameters, args))).Named(name, service); SetLifetimeScope(lifecycle, syntax.RegistrationData); builder.Update(Container.ComponentRegistry); }
public static IComponentConfig <T> Component <T>(DependencyLifecycle lifecycle) { throw new NotImplementedException(); }
/// <summary> /// Gets the instance scope from call model. /// </summary> /// <param name="dependencyLifecycle"> /// The call model. /// </param> /// <returns> /// The instance scope /// </returns> private Func<IContext, object> GetInstanceScopeFrom(DependencyLifecycle dependencyLifecycle) { Func<IContext, object> scope; if (!this.dependencyLifecycleToScopeMapping.TryGetValue(dependencyLifecycle, out scope)) { throw new ArgumentException("The dependency lifecycle is not supported", "dependencyLifecycle"); } return scope; }
public static IComponentConfig <T> Component <T>(Func <IBuilder, T> componentFactory, DependencyLifecycle lifecycle) { throw new NotImplementedException(); }
public void BindToMethod(Type service, Func<IIocContainer, IList<IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(methodBindingDelegate, nameof(methodBindingDelegate)); if (parameters == null) parameters = Empty.Array<IIocParameter>(); IMethodCallbackObjectPriorityUseWithSyntax syntax = _injector.BindWithManualBuild(service).ToMethod(context => methodBindingDelegate(this, GetParameters(parameters, context))).InScope(GetScope(lifecycle)); if (name != null) syntax.NamedBinding(name); syntax.Build(); }
public void ConfigureComponent(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { _container.Register(concreteComponent, Map(dependencyLifecycle)); }
public void Configure(Type component, DependencyLifecycle dependencyLifecycle) { Register(component); }
public void ConfigureComponent <T>(DependencyLifecycle dependencyLifecycle) { ConfigureComponent(typeof(T), dependencyLifecycle); }
public void Configure <T>(Func <T> component, DependencyLifecycle dependencyLifecycle) { throw new NotImplementedException(); }
public void ConfigureComponent <T>(Func <T> componentFactory, DependencyLifecycle dependencyLifecycle) { var componentType = typeof(T); _container.Register <T>((_) => componentFactory(), Map(dependencyLifecycle)); }
/// <summary> /// Indicates that the service should be bound to the specified method. /// </summary> /// <param name="service">The specified service type.</param> /// <param name="methodBindingDelegate">The specified factory delegate.</param> /// <param name="lifecycle"> /// The specified <see cref="DependencyLifecycle" /> /// </param> /// <param name="name">The specified binding name.</param> public void BindToMethod(Type service, Func<IIocContainer, IList<IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(methodBindingDelegate, "methodBindingDelegate"); IBindingWhenInNamedWithOrOnSyntax<object> syntax = _kernel .Bind(service) .ToMethod(context => methodBindingDelegate(this, GetParameters(context))); SetLifecycle(syntax, lifecycle); if (name != null) syntax.Named(name); }
public void ConfigureComponent <T>(Func <IBuilder, T> componentFactory, DependencyLifecycle dependencyLifecycle) { _container.Register <T>((_) => componentFactory(this), Map(dependencyLifecycle)); }
private static ILifecycle GetLifecycleFrom(DependencyLifecycle dependencyLifecycle) { switch (dependencyLifecycle) { case DependencyLifecycle.InstancePerCall: return new UniquePerRequestLifecycle(); case DependencyLifecycle.SingleInstance: return new SingletonLifecycle(); case DependencyLifecycle.InstancePerUnitOfWork: return null;//null means the default lifecycle which is transient } throw new ArgumentException("Unhandled lifecycle - " + dependencyLifecycle); }
protected virtual void SetLifetimeScope(DependencyLifecycle lifecycle, RegistrationData data) { if (lifecycle == DependencyLifecycle.SingleInstance) { data.Sharing = InstanceSharing.Shared; data.Lifetime = new RootScopeLifetime(); return; } if (lifecycle == DependencyLifecycle.TransientInstance) { data.Sharing = InstanceSharing.None; data.Lifetime = new CurrentScopeLifetime(); return; } Should.MethodBeSupported(false, "SetLifetimeScope(DependencyLifecycle dependencyLifecycle, IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> builder)"); }
public void BindToMethod(Type service, Func <IIocContainer, IList <IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, nameof(service)); Should.NotBeNull(methodBindingDelegate, nameof(methodBindingDelegate)); Should.NotBeNull(lifecycle, nameof(lifecycle)); var key = new BindingKey(service, name); lock (_bindingRegistrations) { List <BindingRegistration> list; if (!_bindingRegistrations.TryGetValue(key, out list)) { list = new List <BindingRegistration>(); _bindingRegistrations[key] = list; } list.Add(new BindingRegistration(this, methodBindingDelegate, lifecycle, parameters)); } }
public void BindToMethod(Type service, Func<IIocContainer, IList<IIocParameter>, object> methodBindingDelegate, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(methodBindingDelegate, "methodBindingDelegate"); if (parameters == null) parameters = Empty.Array<IIocParameter>(); var builder = new ContainerBuilder(); IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> syntax = name == null ? builder.Register((context, args) => methodBindingDelegate(this, GetParameters(parameters, args))).As(service) : builder.Register((context, args) => methodBindingDelegate(this, GetParameters(parameters, args))).Named(name, service); SetLifetimeScope(lifecycle, syntax.RegistrationData); builder.Update(_container.ComponentRegistry); }
void IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { var reg = GetRegistrationForType(concreteComponent); if (reg == null) { var lifestyle = GetLifestyleTypeFrom(dependencyLifecycle); var services = GetAllServiceTypesFor(concreteComponent); reg = Component.For(services).ImplementedBy(concreteComponent); reg.LifeStyle.Is(lifestyle); lock (lookup) { lookup[concreteComponent] = reg; services.ForEach(s => types.Add(s)); } } else Logger.Info("Component " + concreteComponent.FullName + " was already registered in the container."); }
public void Bind(Type service, Type typeTo, DependencyLifecycle dependencyLifecycle, string name = null, params IIocParameter[] parameters) { this.NotBeDisposed(); Should.NotBeNull(service, "service"); Should.NotBeNull(typeTo, "typeTo"); var builder = new ContainerBuilder(); IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> syntax = name == null ? builder.RegisterType(typeTo).As(service) : builder.RegisterType(typeTo).Named(name, service); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) { var iocParameter = parameters[index]; var parameter = ConvertParameter(iocParameter); if (iocParameter.ParameterType == IocParameterType.Property) syntax.WithProperty(parameter); else syntax.WithParameter(parameter); } } SetLifetimeScope(dependencyLifecycle, syntax.RegistrationData); builder.Update(_container.ComponentRegistry); }
/// <summary> /// Configures the given type with the given <see cref="DependencyLifecycle"/> /// </summary> public static IComponentConfig <T> Component <T>(Func <IBuilder, T> componentFactory, DependencyLifecycle lifecycle) { if (Instance == null) { throw new InvalidOperationException("You need to call Configure.With() before calling Configure.Component<T>()"); } return(Instance.Configurer.ConfigureComponent(componentFactory, lifecycle)); }
void IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) { var handler = GetHandlerForType(concreteComponent); if (handler == null) { var lifestyle = GetLifestyleTypeFrom(dependencyLifecycle); var reg = Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); reg.LifeStyle.Is(lifestyle); container.Kernel.Register(reg); } }