public virtual void Register(Type component) { if (component == null) { throw new ArgumentNullException(); } Register(ComponentContextUtils.GetComponentDefaultName(component), CreateDefaultFactory(component)); }
public virtual void Register(string name, Type componentType) { if (componentType == null) { throw new ArgumentNullException(nameof(componentType)); } Register(name, ComponentContextUtils.CreateLocalFactory(componentType)); }
public virtual IEnumerable <object> GetAllComponents(Type contract, string name) { ComponentContextUtils.ThrowIfNotContract(contract); var identity = new ContractIdentity(contract, name); var factories = _repository.FindFactories(identity); return(factories .Select(f => f.GetComponentInstance(identity, _compositionListeners.Values)) .Where(result => result != null)); }
public virtual void Register(Type contract, string name, Type component) { if (contract == null) { throw new ArgumentNullException(nameof(contract)); } if (component == null) { throw new ArgumentNullException(nameof(component)); } ComponentContextUtils.ThrowIfNotSubTypeOf(contract, component); InternalRegister(contract, name, CreateDefaultFactory(component), true); }
public virtual object GetComponent(Type contract, string name) { ComponentContextUtils.ThrowIfNotContract(contract); if (contract.ContainsGenericParameters) { throw new CompositionException("Requested contract type " + contract.Name + " contains open generic parameters. Can not construct a concrete type."); } var identity = new ContractIdentity(contract, name); var factories = _repository.FindFactories(identity); return(factories .Select(f => f.GetComponentInstance(identity, _compositionListeners.Values)) .FirstOrDefault(result => result != null)); }
private void RegisterBuildInComponents() { InternalRegister(typeof(DefaultComponentCache), null, ComponentContextUtils.CreateLocalFactory(typeof(DefaultComponentCache)), false); InternalRegister(typeof(ContractAgnosticComponentCache), null, ComponentContextUtils.CreateLocalFactory(typeof(ContractAgnosticComponentCache)), false); InternalRegister(typeof(StaticComponentCache), null, ComponentContextUtils.CreateLocalFactory(typeof(StaticComponentCache)), false); InternalRegister(typeof(ThreadLocalComponentCache), null, ComponentContextUtils.CreateLocalFactory(typeof(ThreadLocalComponentCache)), false); InternalRegister(typeof(IClassEmitter), null, ComponentContextUtils.CreateLocalFactory(typeof(DefaultClassEmitter)), false); InternalRegister(typeof(IMethodEmitter), null, ComponentContextUtils.CreateLocalFactory(typeof(DefaultMethodEmitter)), false); InternalRegister(typeof(IPropertyEmitter), null, ComponentContextUtils.CreateLocalFactory(typeof(DefaultPropertyEmitter)), false); InternalRegister(typeof(IEventEmitter), null, ComponentContextUtils.CreateLocalFactory(typeof(DefaultEventEmitter)), false); }
private void InternalRegister(Type contract, string name, IComponentFactory factory, bool performChecking) { if (contract == null) { throw new ArgumentNullException(nameof(contract)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (performChecking) { ComponentContextUtils.ThrowIfNotContract(contract); } factory.Initialize(this); _repository.Add(new ContractIdentity(contract, name), factory); }
public virtual void InitializePlugs(object componentInstance, Type componentType) { var initializationPoints = ComponentContextUtils.ExtractInitializationPoints(this, componentType); var initializationPointResults = new List <object>(); foreach (var initializationPoint in initializationPoints) { if (initializationPoint.Query == null) { throw new CompositionException( $"Query is null for initialization point '{initializationPoint.Name}' on component instance of type '{componentType.FullName}'"); } var initializationPointResult = initializationPoint.Query.Query(this); initializationPointResults.Add(initializationPointResult); ComponentContextUtils.ApplyInitializationPoint(componentInstance, initializationPoint.Name, initializationPoint.MemberType, initializationPointResult); } foreach (var compositionListener in _compositionListeners.Values) { compositionListener.OnComponentComposed(null, initializationPoints, initializationPointResults, componentType, componentInstance, componentInstance); } var compositionNotificationMethods = ComponentContextUtils.FindCompositionNotificationMethods(componentType); if (compositionNotificationMethods != null) { foreach (var method in compositionNotificationMethods) { method.Invoke(componentInstance, new object[0]); } } }
public virtual void Register(Type contract, Type component) { Register(contract, ComponentContextUtils.GetComponentDefaultName(component), component); }