コード例 #1
0
        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 && !Configuration.DisableAttributeChecking)
            {
                ComponentContextUtils.ThrowIfNotContract(contract);
            }

            if (!factory.ValidateContractType(contract))
            {
                throw new CompositionException("This component type / factory cannot be registered with the contract " +
                                               $"{contract.FullName}. The component type is not assignable to the contract " +
                                               "or the factory logic prevents such registration.");
            }

            factory.Initialize(this);

            _repository.Add(new ContractIdentity(contract, name), factory);
        }
コード例 #2
0
        public virtual void Register(Type component)
        {
            if (component == null)
            {
                throw new ArgumentNullException();
            }

            Register(ComponentContextUtils.GetComponentDefaultName(component), ComponentContextUtils.CreateLocalFactory(component));
        }
コード例 #3
0
        public virtual void Register(string name, Type componentType)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            Register(name, ComponentContextUtils.CreateLocalFactory(componentType));
        }
コード例 #4
0
 private void RegisterBuiltInComponents()
 {
     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);
 }
コード例 #5
0
        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, ComponentContextUtils.CreateLocalFactory(component), true);
        }
コード例 #6
0
        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(this, componentInstance);
                }
            }
        }
コード例 #7
0
 public virtual void Register(Type contract, Type component)
 {
     Register(contract, ComponentContextUtils.GetComponentDefaultName(component), component);
 }