コード例 #1
0
        // This is the ONLY method which is not executed under the ImportEngine composition lock.
        // We need to protect all state that is accesses
        public override object GetExportedValue(ExportDefinition definition)
        {
            this.RequiresRunning();
            // given the implementation of the ImportEngine, this iwll be called under a lock if the part is still being composed
            // This is only called outside of the lock when the part is fully composed
            // based on that we only protect:
            // _exportsCache - and thus all calls to GetExportingMemberFromDefinition
            // access to _importValues
            // access to _initialCompositionComplete
            // access to _instance
            Requires.NotNull(definition, "definition");

            ExportingMember member = null;

            lock (this._lock)
            {
                member = GetExportingMemberFromDefinition(definition);
                if (member == null)
                {
                    throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart("definition");
                }
                this.EnsureGettable();
            }

            return(this.GetExportedValue(member));
        }
コード例 #2
0
        private object GetExportedValue(ExportingMember member)
        {
            object instance = null;

            if (member.RequiresInstance)
            {   // Only activate the instance if we actually need to
                instance = this.GetInstanceActivatingIfNeeded();
            }

            return(member.GetExportedValue(instance, this._lock));
        }
コード例 #3
0
        public override object GetExportedValue(ExportDefinition definition)
        {
            this.EnsureRunning();

            Requires.NotNull(definition, "definition");

            ExportingMember member = GetExportingMemberFromDefinition(definition);

            if (member == null)
            {
                throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart("definition");
            }

            this.EnsureGettable();

            return(this.GetExportedValue(member));
        }
コード例 #4
0
        // alwayc called under a lock
        private bool RequiresActivation()
        {
            // If we have any imports then we need activation
            // (static imports are not supported)
            if (this.ImportDefinitions.Any())
            {
                return(true);
            }

            // If we have any instance exports, then we also
            // need activation.
            return(this.ExportDefinitions.Any(definition =>
            {
                ExportingMember member = GetExportingMemberFromDefinition(definition);

                return member.RequiresInstance;
            }));
        }