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));
        }
Пример #2
0
        /// <summary>
        /// Add the specified component registration.
        /// </summary>
        /// <param name="registration">Registration.</param>
        public void Add(IServiceRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            registration.AssertIsValid();

            var key = ServiceRegistrationKey.ForRegistration(registration);

            lock (syncRoot)
            {
                IServiceRegistration removed;
                registrations.TryRemove(key, out removed);
                registrations.TryAdd(key, registration);
            }
        }