/// <summary>
 /// Configure the request type <paramref name="types"/> to the resolution <paramref name="resolution"/>
 /// </summary>
 /// <param name="types">The request type that will need to be resolved.</param>
 /// <param name="resolution">The resolution that will be implemented.</param>
 public void Add(ICollection <Type> types, IDependencyResolution resolution)
 {
     foreach (var type in types)
     {
         Add(type, resolution);
     }
 }
		/// <summary>
		/// Initializes a new instance of the SingletonWrapperDependencyResolution class.
		/// Lazy loading semantics are assumed by design.
		/// </summary>
		/// <param name="innerDependencyResolution"> The chained dependency resolution which is called only once. </param>
		public SingletonWrapperDependencyResolution(IDependencyResolution innerDependencyResolution)
			: base(DependencyLifetime.Singleton)
		{
			if ((object)innerDependencyResolution == null)
				throw new ArgumentNullException(nameof(innerDependencyResolution));

			this.innerDependencyResolution = innerDependencyResolution;
		}
        private IDependencyResolution CreateConcreteResolution(Type requestType, IDependencyResolution resolution)
        {
            var concreteResolution = resolution.MakeConcrete(requestType);

            Add(requestType, concreteResolution);

            return(concreteResolution);
        }
示例#4
0
        public IRuntimeResolutionPlan FromResolution(IDependencyResolution resolution)
        {
            if (resolution is IDependencyResolution <IDependencyTypeInfo> typedResolution)
            {
                return(CreateTypedPlan(typedResolution.Info.ResolutionType));
            }

            return(new RuntimeResolutionPlanResolution(resolution));
        }
        /// <summary>
        /// Initializes a new instance of the SingletonWrapperDependencyResolution class.
        /// Lazy loading semantics are assumed by design.
        /// </summary>
        /// <param name="innerDependencyResolution"> The chained dependency resolution which is called only once. </param>
        public SingletonWrapperDependencyResolution(IDependencyResolution innerDependencyResolution)
            : base(DependencyLifetime.Singleton)
        {
            if ((object)innerDependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(innerDependencyResolution));
            }

            this.innerDependencyResolution = innerDependencyResolution;
        }
示例#6
0
        /// <summary>
        ///     Adds a new dependency resolution for a given target type and selector key. Throws a DependencyException if the target type and selector key combination has been previously registered in this instance. This is the non-generic overload.
        /// </summary>
        /// <param name="targetType"> The target type of resolution. </param>
        /// <param name="selectorKey"> An non-null, zero or greater length string selector key. </param>
        /// <param name="dependencyResolution"> The dependency resolution. </param>
        public void AddResolution(Type targetType, string selectorKey, IDependencyResolution dependencyResolution)
        {
            KeyValuePair <Type, string> trait;
            LockCookie lockCookie;

            if (this.disposed)
            {
                throw new ObjectDisposedException(typeof(DependencyManager).FullName);
            }

            if ((object)targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException("selectorKey");
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException("dependencyResolution");
            }

            // cop a reader lock
            this.readerWriterLock.AcquireReaderLock(LOCK_AQUIRE_TIMEOUT_MILLISECONDS);

            try
            {
                // cop a writer lock
                lockCookie = this.readerWriterLock.UpgradeToWriterLock(LOCK_AQUIRE_TIMEOUT_MILLISECONDS);

                try
                {
                    trait = new KeyValuePair <Type, string>(targetType, selectorKey);

                    if (this.dependencyResolutionRegistrations.ContainsKey(trait))
                    {
                        throw new DependencyException(string.Format("Dependency resolution already exists in the dependency manager for target type '{0}' and selector key '{1}'.", targetType.FullName, selectorKey));
                    }

                    this.dependencyResolutionRegistrations.Add(trait, dependencyResolution);
                }
                finally
                {
                    this.readerWriterLock.DowngradeFromWriterLock(ref lockCookie);
                }
            }
            finally
            {
                this.readerWriterLock.ReleaseReaderLock();
            }
        }
		public ContextWrapperDependencyResolution(IContextualStorageStrategy contextualStorageStrategy, IDependencyResolution innerDependencyResolution)
			: base(DependencyLifetime.Singleton)
		{
			if ((object)contextualStorageStrategy == null)
				throw new ArgumentNullException(nameof(contextualStorageStrategy));

			if ((object)innerDependencyResolution == null)
				throw new ArgumentNullException(nameof(innerDependencyResolution));

			this.contextualStorageStrategy = contextualStorageStrategy;
			this.innerDependencyResolution = innerDependencyResolution;
		}
示例#8
0
        private IEnumerable YieldResolve()
        {
            Array resolved = Array.CreateInstance(_requestType, _resolutions.Count);

            for (int i = 0; i < _resolutions.Count; i++)
            {
                IDependencyResolution resolution = _resolutions[i];
                resolved.SetValue(resolution.Resolve(), i);
            }

            return(resolved);
        }
示例#9
0
        /// <summary>
        ///     Adds a new dependency resolution for a given target type and selector key. Throws a DependencyException if the target type and selector key combination has been previously registered in this instance. This is the generic overload.
        /// </summary>
        /// <typeparam name="TObject"> The target type of resolution. </typeparam>
        /// <param name="selectorKey"> An non-null, zero or greater length string selector key. </param>
        /// <param name="dependencyResolution"> The dependency resolution. </param>
        public void AddResolution <TObject>(string selectorKey, IDependencyResolution dependencyResolution)
        {
            Type targetType;

            if (this.disposed)
            {
                throw new ObjectDisposedException(typeof(DependencyManager).FullName);
            }

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException("selectorKey");
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException("dependencyResolution");
            }

            targetType = typeof(TObject);

            this.AddResolution(targetType, selectorKey, dependencyResolution);
        }
 public RuntimeResolutionPlanSingleParameter(IRuntimeResolutionPlanCreator planCreator, IDependencyResolution resolution)
 {
     _planCreator = planCreator ?? throw new ArgumentNullException(nameof(planCreator));
     _resolution  = resolution ?? throw new ArgumentNullException(nameof(resolution));
 }
		/// <summary>
		/// Initializes a new instance of the ContextWrapperDependencyResolution class.
		/// </summary>
		/// <param name="contextScope"> The context scope being requested. </param>
		/// <param name="innerDependencyResolution"> The chained dependency resolution which is called only once. </param>
		public ContextWrapperDependencyResolution(ContextScope contextScope, IDependencyResolution innerDependencyResolution)
			: this(new DefaultContextualStorageFactory(contextScope).GetContextualStorage(), innerDependencyResolution)
		{
		}
示例#12
0
        /// <summary>
        /// Adds a new dependency resolution for a given resolution type and selector key. Throws a DependencyException if the resolution type and selector key combination has been previously registered in this instance. This is the generic overload.
        /// </summary>
        /// <typeparam name="TResolution"> The resolution type of resolution. </typeparam>
        /// <param name="selectorKey"> An non-null, zero or greater length string selector key. </param>
        /// <param name="includeAssignableTypes"> A boolean value indicating whether to include assignable types in the candidate resolution existence check. </param>
        /// <param name="dependencyResolution"> The dependency resolution. </param>
        public void AddResolution <TResolution>(string selectorKey, bool includeAssignableTypes, IDependencyResolution <TResolution> dependencyResolution)
        {
            Type resolutionType;

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException(nameof(selectorKey));
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(dependencyResolution));
            }

            resolutionType = typeof(TResolution);

            this.AddResolution(resolutionType, selectorKey, includeAssignableTypes, dependencyResolution);
        }
示例#13
0
        /// <summary>
        /// Adds a new dependency resolution for a given resolution type and selector key. Throws a DependencyException if the resolution type and selector key combination has been previously registered in this instance. This is the non-generic overload.
        /// </summary>
        /// <param name="resolutionType"> The resolution type of resolution. </param>
        /// <param name="selectorKey"> An non-null, zero or greater length string selector key. </param>
        /// <param name="includeAssignableTypes"> A boolean value indicating whether to include assignable types in the candidate resolution existence check. </param>
        /// <param name="dependencyResolution"> The dependency resolution. </param>
        public void AddResolution(Type resolutionType, string selectorKey, bool includeAssignableTypes, IDependencyResolution dependencyResolution)
        {
            Tuple <Type, string> trait;
            IEnumerable <KeyValuePair <Tuple <Type, string>, IDependencyResolution> > candidateResolutions;

            if ((object)resolutionType == null)
            {
                throw new ArgumentNullException(nameof(resolutionType));
            }

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException(nameof(selectorKey));
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(dependencyResolution));
            }

            // cop a reader lock
            this.ReaderWriterLock.EnterUpgradeableReadLock();

            try
            {
                if (this.IsDisposed)
                {
                    throw new ObjectDisposedException(typeof(DependencyManager).FullName);
                }

                // cop a writer lock
                this.ReaderWriterLock.EnterWriteLock();

                try
                {
                    trait = new Tuple <Type, string>(resolutionType, selectorKey);
                    candidateResolutions = this.GetCandidateResolutionsMustReadLock(resolutionType, selectorKey, includeAssignableTypes);

                    if (candidateResolutions.Any())
                    {
                        throw new DependencyException(string.Format("Dependency resolution already exists in the dependency manager for resolution type '{0}' and selector key '{1}' (include assignable types: '{2}').", resolutionType.FullName, selectorKey, includeAssignableTypes));
                    }

                    this.DependencyResolutionRegistrations.Add(trait, dependencyResolution);
                }
                finally
                {
                    this.ReaderWriterLock.ExitWriteLock();
                }
            }
            finally
            {
                this.ReaderWriterLock.ExitUpgradeableReadLock();
            }
        }
        /// <summary>
        /// Configure the request type <paramref name="type"/> to the resolution <paramref name="resolution"/>
        /// </summary>
        /// <param name="type">The request type that will need to be resolved.</param>
        /// <param name="resolution">The resolution that will be implemented.</param>
        public void Add(Type type, IDependencyResolution resolution)
        {
            _hasGenericFactoryTypes |= resolution is DependencyFactoryResolution;

            AddToTypeMap(type, resolution);
        }
示例#15
0
        public ContextWrapperDependencyResolution(IContextualStorageStrategy contextualStorageStrategy, IDependencyResolution innerDependencyResolution)
            : base(DependencyLifetime.Singleton)
        {
            if ((object)contextualStorageStrategy == null)
            {
                throw new ArgumentNullException(nameof(contextualStorageStrategy));
            }

            if ((object)innerDependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(innerDependencyResolution));
            }

            this.contextualStorageStrategy = contextualStorageStrategy;
            this.innerDependencyResolution = innerDependencyResolution;
        }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the ContextWrapperDependencyResolution class.
 /// </summary>
 /// <param name="contextScope"> The context scope being requested. </param>
 /// <param name="innerDependencyResolution"> The chained dependency resolution which is called only once. </param>
 public ContextWrapperDependencyResolution(ContextScope contextScope, IDependencyResolution innerDependencyResolution)
     : this(new DefaultContextualStorageFactory(contextScope).GetContextualStorage(), innerDependencyResolution)
 {
 }
示例#17
0
        public async ValueTask AddResolutionAsync <TResolution>(string selectorKey, bool includeAssignableTypes, IDependencyResolution <TResolution> dependencyResolution, CancellationToken cancellationToken = default)
        {
            Type resolutionType;

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException(nameof(selectorKey));
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(dependencyResolution));
            }

            resolutionType = typeof(TResolution);

            await this.AddResolutionAsync(resolutionType, selectorKey, includeAssignableTypes, dependencyResolution, cancellationToken);
        }
示例#18
0
 public GraphHandler(string packageId, IDependencyResolution dependencyResolution)
 {
     m_DependencyResolution = dependencyResolution;
     Result = new ResolutionResult(packageId, null);
 }
        private bool AddToTypeMap(Type type, IDependencyResolution resolution)
        {
            var resolutions = _typeMap.GetOrAdd(type, t => new HashSet <IDependencyResolution>());

            return(resolutions.Add(resolution));
        }
示例#20
0
        public async ValueTask AddResolutionAsync(Type resolutionType, string selectorKey, bool includeAssignableTypes, IDependencyResolution dependencyResolution, CancellationToken cancellationToken = default)
        {
            Tuple <Type, string> trait;
            IAsyncEnumerable <KeyValuePair <Tuple <Type, string>, IDependencyResolution> > candidateResolutions;

            if ((object)resolutionType == null)
            {
                throw new ArgumentNullException(nameof(resolutionType));
            }

            if ((object)selectorKey == null)
            {
                throw new ArgumentNullException(nameof(selectorKey));
            }

            if ((object)dependencyResolution == null)
            {
                throw new ArgumentNullException(nameof(dependencyResolution));
            }

            // cop a writer lock
            using (await this.AsyncReaderWriterLock.WriterLockAsync(cancellationToken))
            {
                if (this.IsAsyncDisposed)
                {
                    throw new ObjectDisposedException(typeof(DependencyManager).FullName);
                }

                // ...
                {
                    trait = new Tuple <Type, string>(resolutionType, selectorKey);
                    candidateResolutions = this.GetCandidateResolutionsMustReadLockAsync(resolutionType, selectorKey, includeAssignableTypes, cancellationToken);

                    if (await candidateResolutions.CountAsync(cancellationToken) > 0)
                    {
                        throw new DependencyException(string.Format("Dependency resolution already exists in the dependency manager for resolution type '{0}' and selector key '{1}' (include assignable types: '{2}').", resolutionType.FullName, selectorKey, includeAssignableTypes));
                    }

                    this.DependencyResolutionRegistrations.Add(trait, dependencyResolution);
                }
            }
        }
示例#21
0
 public RuntimeResolutionPlanResolution(IDependencyResolution resolution)
 {
     _resolution = resolution ?? throw new ArgumentNullException(nameof(resolution));
 }