Beispiel #1
0
        /// <summary>
        /// Add registration to cache.
        /// </summary>
        /// <param name="registration">Registration to add.</param>
        private void addRegistration(IRegistration registration)
        {
            if (typeIsRegistered(registration.RegisteredType))
            {
                if (Options.ThrowExceptionOnDuplicateRegistration)
                {
                    Type type = registration.RegisteredType;

                    throw new DuplicateRegistrationException(type, $"{type.Name} is already registered.");
                }
            }

            _registrations.Add(registration.RegisteredType, registration);
        }
Beispiel #2
0
        private void Register(IMounter <TTarget, TProperty> item)
        {
            Type targetType = item.ParentType;

            if (_resultRegistrations.ContainsKey(targetType))
            {
                throw new InvalidOperationException(DiagnosticMessages.MounterManager_RegisterAfterUse(targetType.FullName));
            }

            RegistrationCollection registrations = _registrations.GetOrAdd(targetType, x => new RegistrationCollection());

            if (registrations.Contains(new Key(item)))
            {
                throw new InvalidOperationException(DiagnosticMessages.MounterManager_RegisterDuplicate(item.DeclaringType.FullName, item.Name));
            }

            registrations.Add(item);
        }