Beispiel #1
0
        public static string GetMappingAsString(this IContainerRegistration registration)
        {
            string regName, regType, mapTo, lifetime;

            var r = registration.RegisteredType;

            regType = r.Name + GetGenericArgumentsList(r);

            var m = registration.MappedToType;

            mapTo = m.Name + GetGenericArgumentsList(m);

            regName = registration.Name ?? "[default]";

            lifetime = registration.LifetimeManager.LifetimeType.Name;

            if (mapTo != regType)
            {
                mapTo = " -> " + mapTo;
            }
            else
            {
                mapTo = string.Empty;
            }

            lifetime = lifetime.Substring(0, lifetime.Length - "LifetimeManager".Length);
            return($"+ {regType}{mapTo} '{regName}' {lifetime}");
        }
        private bool IsUnityContainerRegistration(IContainerRegistration registration)
        {
            bool registeredType = registration.RegisteredType == typeof(IUnityContainer);
            bool mappedToType   = registration.MappedToType == typeof(UnityContainer);

            return(registeredType && mappedToType);
        }
        protected void IsUnityContainerRegistration(IContainerRegistration registration)
        {
            bool registeredType = registration.RegisteredType == typeof(IUnityContainer);
            bool mappedToType   = registration.MappedToType == typeof(UnityContainer);

            IsTrue(registeredType);
            IsTrue(mappedToType);
        }
Beispiel #4
0
 private static ILifetime GetLifetime(IContainerRegistration reg)
 {
     return(reg.Lifetime == Lifetime.Transient
         ? new PerContainerLifetime()
         : reg.Lifetime == Lifetime.ExternallyOwned
             ? new ExternallyOwnedLifetime()
             : reg.Lifetime == Lifetime.Request
                 ? new PerRequestLifeTime()
                 : (ILifetime) new PerContainerLifetime());
 }
Beispiel #5
0
 private static ITypeLifetimeManager GetLifetime(IContainerRegistration reg)
 {
     return(reg.Lifetime == Lifetime.Transient
         ? new TransientLifetimeManager()
         : reg.Lifetime == Lifetime.ExternallyOwned
             ? new ExternallyControlledLifetimeManager()
             : reg.Lifetime == Lifetime.Request
                 ? new PerRequestLifetimeManager()
                 : (ITypeLifetimeManager) new TransientLifetimeManager());
 }
Beispiel #6
0
        public ICqrsBuilder RegisterContainer(IContainerRegistration containerRegistration)
        {
            this._containerRegistration = containerRegistration ?? throw new ArgumentNullException(nameof(containerRegistration));

            foreach (var handler in this._handlerTypes)
            {
                this._containerRegistration.RegisterAction(handler);
            }

            return(this);
        }
        private bool IsExpectedRegisteredContainer(IContainerRegistration registration,
                                                   Type expectedFrom,
                                                   Type expectedTo,
                                                   Type expectedTypeLifetimeManagerType)
        {
            bool registeredType  = registration.RegisteredType == expectedFrom;
            bool mappedToType    = registration.MappedToType == expectedTo;
            bool lifetimeManager = registration.LifetimeManager.GetType() == expectedTypeLifetimeManagerType;

            return(registeredType && mappedToType && lifetimeManager);
        }
        protected void IsExpectedRegisteredContainer(IContainerRegistration registration,
                                                     Type expectedFrom,
                                                     Type expectedTo,
                                                     Type expectedTypeLifetimeManagerType)
        {
            bool registeredType  = registration.RegisteredType == expectedFrom;
            bool mappedToType    = registration.MappedToType == expectedTo;
            bool lifetimeManager = registration.LifetimeManager.GetType() == expectedTypeLifetimeManagerType;

            IsTrue(registeredType);
            IsTrue(mappedToType);
            IsTrue(lifetimeManager);
        }
Beispiel #9
0
        void IContainerRegistry.AddRegistration(IContainerRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException("registration");
            }

            if (_container != null)
            {
                throw new InvalidOperationException("Registrations can only be added prior to the container being built and accessed.");
            }

            string registrationName = registration.GetType().Name;

            if (_registrations.ContainsKey(registrationName))
            {
                return;
            }

            _registrations.Add(registrationName, registration);
        }
Beispiel #10
0
        private static IInterceptor[] GetInterceptors(IUnityContainer unityContainer, IInterceptor[] globalInterceptors, IContainerRegistration registration, InterceptionOptions options)
        {
            var attributeInterceptors = ReflectionHelper.GetAttributeInterceptors(registration.MappedToType, unityContainer);

            var interceptors = new List <IInterceptor>();

            if (options.GlobalInterceptorsOrder == GlobalInterceptorsOrder.AfterAttributeInterceptors)
            {
                interceptors.AddRange(attributeInterceptors);
                interceptors.AddRange(globalInterceptors);
            }
            else
            {
                interceptors.AddRange(globalInterceptors);
                interceptors.AddRange(attributeInterceptors);
            }

            return(ReflectionHelper.RemoveExcludedGlobalInterceptors(registration.MappedToType, interceptors.ToArray()));
        }