void Common.IContainer.Configure(Type component, ComponentCallModelEnum callModel) { lock (configuredInstances) { if(configuredInstances.ContainsKey(component)) return; } var lifecycle = GetLifecycleFrom(callModel); ConfiguredInstance configuredInstance = null; container.Configure(x => { configuredInstance = x.For(component) .LifecycleIs(lifecycle) .Use(component); foreach (var implementedInterface in GetAllInterfacesImplementedBy(component)) { x.RegisterAdditionalInterfaceForPluginType(implementedInterface, component,lifecycle); x.EnableSetterInjectionFor(implementedInterface); } }); lock (configuredInstances) configuredInstances.Add(component, configuredInstance); }
/// <summary> /// Register the given type in the container /// </summary> /// <param name="component"></param> /// <param name="callModel"></param> void Common.IContainer.Configure(Type component, ComponentCallModelEnum callModel) { lock (configuredInstances) { if (configuredInstances.ContainsKey(component)) return; } var scope = GetInstanceScopeFrom(callModel); ConfiguredInstance configuredInstance = null; container.Configure(x => { configuredInstance = x.ForRequestedType(component) .CacheBy(scope) .TheDefaultIsConcreteType(component); foreach (var implementedInterface in GetAllInterfacesImplementedBy(component)) { x.RegisterAdditionalInterfaceForPluginType(implementedInterface, component); x.EnableSetterInjectionFor(implementedInterface); } }); lock (configuredInstances) configuredInstances.Add(component, configuredInstance); }
public void Configure(Type concreteComponent, ComponentCallModelEnum callModel) { 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(callModel)); } else { container.RegisterType(t, concreteComponent, GetLifetimeManager(callModel)); typesWithDefaultInstances.Add(t); } } } }
public void Configure(Type component, ComponentCallModelEnum callModel) { if (!_registrar.HasRegistered(component)) { _registrar.BehaveAs(GetLifetime(callModel)).Register(component, component); } }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { typeHandleLookup[concreteComponent] = callModel; lock (componentProperties) if (!componentProperties.ContainsKey(concreteComponent)) componentProperties[concreteComponent] = new ComponentConfig(); }
IComponentConfig <T> IConfigureComponents.ConfigureComponent <T>(ComponentCallModelEnum callModel) { var lifecycle = MapToDependencyLifecycle(callModel); Container.Configure(typeof(T), lifecycle); return(new ComponentConfig <T>(Container)); }
public IComponentConfig ConfigureComponent(Type concreteComponent, ComponentCallModelEnum callModel) { var lifecycle = MapToDependencyLifecycle(callModel); container.Configure(concreteComponent, lifecycle); return(new ComponentConfig(concreteComponent, container)); }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { if (this.GetHandlerForType(concreteComponent) == null) { LifestyleType lifestyleTypeFrom = GetLifestyleTypeFrom(callModel); ComponentRegistration<object> registration = Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); registration.get_LifeStyle().Is(lifestyleTypeFrom); this.Container.get_Kernel().Register(new IRegistration[] { registration }); } }
private static ServiceRegistrarLifetime GetLifetime(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singleton: return(ServiceRegistrarLifetime.Singleton); case ComponentCallModelEnum.Singlecall: return(ServiceRegistrarLifetime.Transient); default: return(ServiceRegistrarLifetime.Transient); } }
private static LifestyleType GetLifestyleTypeFrom(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singlecall: return(LifestyleType.Transient); case ComponentCallModelEnum.Singleton: return(LifestyleType.Singleton); } return(LifestyleType.Undefined); }
void IContainer.Configure(Type component, ComponentCallModelEnum callModel) { _callModels[component] = callModel; lock (_componentDefinitions) { if (!_componentDefinitions.ContainsKey(component)) { _componentDefinitions[component] = new ComponentConfig(); } } }
private static LifestyleType GetLifestyleTypeFrom(ComponentCallModelEnum callModel) { switch (callModel - 1) { case ComponentCallModelEnum.Singleton: return LifestyleType.Singleton; case ComponentCallModelEnum.Singlecall: return LifestyleType.Transient; default: return LifestyleType.Singleton; } }
private static LifestyleType GetLifestyleTypeFrom(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singleton: return 1; case ComponentCallModelEnum.Singlecall: return 3; } return 0; }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { if (this.GetHandlerForType(concreteComponent) != null) return; LifestyleType lifestyleTypeFrom = WindsorObjectBuilder.GetLifestyleTypeFrom(callModel); ComponentRegistration<object> componentRegistration = Component.For(WindsorObjectBuilder.GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); componentRegistration.LifeStyle.Is(lifestyleTypeFrom); this.Container.Kernel.Register(new IRegistration[1] { (IRegistration) componentRegistration }); }
void Common.IContainer.Configure(Type component, ComponentCallModelEnum callModel) { IComponentRegistration registration = this.GetComponentRegistration(component); if (registration == null) { var builder = new ContainerBuilder(); Type[] services = component.GetAllServices().ToArray(); var registrationBuilder = builder.RegisterType(component).As(services).PropertiesAutowired(); SetLifetimeScope(callModel, registrationBuilder); builder.Update(this.Container); } }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { var handler = GetHandlerForType(concreteComponent); if (handler == null) { var lifestyle = GetLifestyleTypeFrom(callModel); var reg = Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); reg.LifeStyle.Is(lifestyle); Container.Kernel.Register(reg); } }
void Common.IContainer.Configure(Type component, ComponentCallModelEnum callModel) { IComponentRegistration registration = this.GetComponentRegistration(component); if (registration == null) { var builder = new ContainerBuilder(); InstanceScope instanceScope = GetInstanceScopeFrom(callModel); Type[] services = component.GetAllServices().ToArray(); builder.Register(component).As(services).WithScope(instanceScope).OnActivating(ActivatingHandler.InjectUnsetProperties); builder.Build(this.Container); } }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { if (GetHandlerForType(concreteComponent) != null) { return; } var lifestyleTypeFrom = GetLifestyleTypeFrom(callModel); var registration = Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); registration.LifeStyle.Is(lifestyleTypeFrom); Container.Kernel.Register(registration); }
public void Configure(Type component, ComponentCallModelEnum callModel) { if (callModel == ComponentCallModelEnum.Singleton) { _kernel.Bind(component).ToSelf().InSingletonScope(); } else if (callModel == ComponentCallModelEnum.Singlecall) { _kernel.Bind(component).ToSelf().InTransientScope(); } else throw new ArgumentException("callModel"); _heuristic.RegisteredTypes.Add(component); }
private static void SetLifetimeScope(ComponentCallModelEnum callModel, IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrationBuilder) { switch (callModel) { case ComponentCallModelEnum.Singlecall: registrationBuilder.InstancePerDependency(); break; case ComponentCallModelEnum.Singleton: registrationBuilder.SingleInstance(); break; default: registrationBuilder.InstancePerLifetimeScope(); break; } }
public void Configure(Type type, ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singleton: _resolvers[type] = new SingletonResolver(type, _container, Build); _container.Register.Type(type).AsSingleton(); break; case ComponentCallModelEnum.Singlecall: _resolvers[type] = new TransientResolver(type, _container, Build); _container.Register.Type(type).AsTransient(); break; default: throw new ArgumentException(); } }
static DependencyLifecycle MapToDependencyLifecycle(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singleton: return(DependencyLifecycle.SingleInstance); case ComponentCallModelEnum.Singlecall: return(DependencyLifecycle.InstancePerCall); case ComponentCallModelEnum.None: return(DependencyLifecycle.InstancePerUnitOfWork); } throw new ArgumentException("Unhandled component call model: " + callModel); }
private static LifetimeManager GetLifetimeManager(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singlecall: return new TransientLifetimeManager(); case ComponentCallModelEnum.Singleton: return new ContainerControlledLifetimeManager(); default: return new TransientLifetimeManager(); } }
void IContainer.Configure(Type concreteComponent, ComponentCallModelEnum callModel) { if (GetHandlerForType(concreteComponent) != null) return; var lifestyleTypeFrom = GetLifestyleTypeFrom(callModel); var registration = Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent); registration.LifeStyle.Is(lifestyleTypeFrom); Container.Kernel.Register(registration); }
public void Configure(Type component, ComponentCallModelEnum callModel) { ServiceLocator.Register(component, component); }
public void Configure(Type component, ComponentCallModelEnum callModel) { }
private static InstanceScope GetInstanceScopeFrom(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singlecall: return InstanceScope.PerRequest; case ComponentCallModelEnum.Singleton: return InstanceScope.Singleton; } throw new ArgumentException("Unhandled call model:" + callModel); }
private void RegisterObjectDefinitionInContext(Type objectType, ComponentConfig componentConfig, ComponentCallModelEnum callModelEnum) { var builder = ObjectDefinitionBuilder.RootObjectDefinition(_factory, objectType) .SetAutowireMode(AutoWiringMode.AutoDetect) .SetSingleton(callModelEnum == ComponentCallModelEnum.Singleton); componentConfig.Configure(builder); IObjectDefinition objectDefinition = builder.ObjectDefinition; _context.RegisterObjectDefinition(objectType.FullName, objectDefinition); }
/// <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, ComponentCallModelEnum callModel) { if (this.HasComponent(component)) { return; } var instanceScope = this.GetInstanceScopeFrom(callModel); this.BindComponentToItself(component, instanceScope); this.BindAliasesOfComponentToComponent(component, instanceScope); this.propertyHeuristic.RegisteredTypes.Add(component); }
private static InstanceScope GetInstanceScopeFrom(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singlecall: return InstanceScope.Factory; case ComponentCallModelEnum.Singleton: return InstanceScope.Singleton; } return InstanceScope.Container; }
private static ILifecycle GetLifecycleFrom(ComponentCallModelEnum callModel) { switch (callModel) { case ComponentCallModelEnum.Singlecall: return null;//null means the default lifecycle which is transient case ComponentCallModelEnum.Singleton: return new SingletonLifecycle(); } throw new ArgumentException("Unhandled call model:" + callModel); }
/// <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(ComponentCallModelEnum callModel) { Func<IContext, object> scope; if (!this.componentCallModelToScopeMapping.TryGetValue(callModel, out scope)) { throw new ArgumentException("The component call model is not supported", "callModel"); } return scope; }