ResolutionResult ResolveNamedInstanceDictionary(ResolutionRequest request)
        {
            var keyType    = dictionaryFactory.GetKeyType(request.ServiceType);
            var valueType  = dictionaryFactory.GetValueType(request.ServiceType);
            var dictionary = dictionaryFactory.Create(keyType, valueType);

            var allServiceTypeRegistrations = registrationAccessor.GetAll(valueType);

            foreach (var registration in allServiceTypeRegistrations)
            {
                var serviceResult = ResolveSingleInstance(registration, request);
                if (!serviceResult.IsSuccess)
                {
                    // TODO: Throw an exception? Return a failed resolution result? Currently I'm silently skipping the registration.
                    continue;
                }

                var dictionaryKey = ConvertToNameType(registration.Name, keyType);
                dictionary.Add(dictionaryKey, serviceResult.ResolvedObject);
            }

            var dictionaryRegistration = CreateNamedInstanceDictionaryRegistration(request.ServiceType, dictionary);
            var resolutionPath         = request.ResolutionPath.CreateChild(dictionaryRegistration);

            return(ResolutionResult.Success(resolutionPath, dictionary));
        }
        IDictionary <ServiceRegistrationKey, IServiceRegistration> GetNonConflictingRegistrations(IEnumerable <ServiceRegistrationKey> alreadyFound,
                                                                                                  IServiceRegistrationProvider provider,
                                                                                                  Type serviceTypeFilter)
        {
            if (alreadyFound == null)
            {
                throw new ArgumentNullException(nameof(alreadyFound));
            }
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var candidates = (serviceTypeFilter != null)? provider.GetAll(serviceTypeFilter) : provider.GetAll();

            if (candidates == null)
            {
                candidates = new IServiceRegistration[0];
            }

            return((from registration in candidates
                    let key = ServiceRegistrationKey.ForRegistration(registration)
                              where !alreadyFound.Contains(key)
                              select new { Registration = registration, Key = key })
                   .ToDictionary(k => k.Key, v => v.Registration));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a collection of the service/component registrations which are eligible for disposal.
        /// </summary>
        /// <returns>The registrations to dispose.</returns>
        /// <param name="registrationProvider">Registration provider.</param>
        protected virtual IReadOnlyCollection <IServiceRegistration> GetRegistrationsToDispose(IServiceRegistrationProvider registrationProvider)
        {
            if (registrationProvider == null)
            {
                throw new ArgumentNullException(nameof(registrationProvider));
            }

            return(registrationProvider
                   .GetAll()
                   .Where(x => x.Cacheable && x.DisposeWithContainer)
                   .ToArray());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a collection of all of the registrations held within the current container instance.
        /// </summary>
        /// <returns>The registrations.</returns>
        public IReadOnlyCollection <IServiceRegistration> GetRegistrations()
        {
            AssertNotDisposed();

            return(registryStack.GetAll());
        }