Пример #1
0
        /// <summary>
        /// Registers a component in the component catalog.
        /// </summary>
        /// <typeparam name="I">Interface type of the component</typeparam>
        /// <param name="uniqueName">Unique component name</param>
        /// <param name="factoryMethod">Delegate of factory method for external instance creation</param>
        /// <param name="activationType">Activation type (SingleCall/Singleton)</param>
        /// <param name="cleanUpHandler">Delegate for external clean up method</param>
        public void RegisterComponent <I>(string uniqueName, Func <object> factoryMethod, ActivationType activationType, Action <object> cleanUpHandler)
        {
            Type interfaceType = typeof(I);

            if (!interfaceType.IsInterface)
            {
                throw new ApplicationException(LanguageResource.ArgumentException_TypeIsNotAInterface);
            }

            if (factoryMethod == null)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_FactoryMethodDelegateMissing, "factoryMethod");
            }

            if (string.IsNullOrEmpty(uniqueName))
            {
                uniqueName = interfaceType.FullName;
            }

            if (!ComponentRegistry.ContainsKey(uniqueName))
            {
                ComponentRegistration registration = new ComponentRegistration(interfaceType, factoryMethod, uniqueName, activationType, cleanUpHandler);
                registration.DisposeWithCatalog = true;
                ComponentRegistry.Add(uniqueName, registration);
            }

            RegisterQueryableMethods <I>(uniqueName);
        }
Пример #2
0
        /// <summary>
        /// Registers a component in the component catalog.
        /// </summary>
        /// <typeparam name="I">Interface type of the component</typeparam>
        /// <param name="uniqueName">Unique component name</param>
        /// <param name="factoryMethod">Delegate of factory method for external instance creation</param>
        /// <param name="activationType">Activation type (SingleCall/Singleton)</param>
        /// <param name="cleanUpHandler">Delegate for external clean up method</param>
        public void RegisterComponent <I>(string uniqueName, Func <object> factoryMethod, ActivationType activationType, Action <object> cleanUpHandler)
        {
            Type interfaceType = typeof(I);

            if (!interfaceType.IsInterface)
            {
                throw new ApplicationException(LanguageResource.ArgumentException_TypeIsNotAInterface);
            }

            if (factoryMethod == null)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_FactoryMethodDelegateMissing, "factoryMethod");
            }

            if (string.IsNullOrEmpty(uniqueName))
            {
                uniqueName = interfaceType.FullName;
            }

            // register the component and its queryable methods
            var registration = new ComponentRegistration(interfaceType, factoryMethod, uniqueName, activationType, cleanUpHandler);

            registration.DisposeWithCatalog = true;
            ComponentRegistry.Register(uniqueName, registration, ZyanSettings.LegacyIgnoreDuplicateRegistrations);

            RegisterQueryableMethods <I>(uniqueName);
        }
Пример #3
0
        /// <summary>
        /// Registers a component in the component catalog.
        /// </summary>
        /// <typeparam name="I">Interface type of the component</typeparam>
        /// <typeparam name="T">Implementation type of the component</typeparam>
        /// <param name="uniqueName">Unique component name</param>
        /// <param name="activationType">Activation type (SingleCall/Singleton)</param>
        /// <param name="cleanUpHandler">Delegate for external clean up method</param>
        public void RegisterComponent <I, T>(string uniqueName, ActivationType activationType, Action <object> cleanUpHandler)
        {
            Type interfaceType      = typeof(I);
            Type implementationType = typeof(T);

            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_TypeIsNotAInterface, "interfaceType");
            }

            if (!implementationType.IsClass)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_TypeIsNotAClass, "interfaceType");
            }

            new TypeComparer <I, T>().Validate();

            if (string.IsNullOrEmpty(uniqueName))
            {
                uniqueName = interfaceType.FullName;
            }

            if (!ComponentRegistry.ContainsKey(uniqueName))
            {
                ComponentRegistration registration = new ComponentRegistration(interfaceType, implementationType, uniqueName, activationType, cleanUpHandler);
                registration.DisposeWithCatalog = true;
                ComponentRegistry.Add(uniqueName, registration);
            }

            RegisterQueryableMethods <I>(uniqueName);
        }
Пример #4
0
 /// <summary>
 /// Deletes a component registration.
 /// </summary>
 /// <param name="uniqueName">Unique component name</param>
 public void UnregisterComponent(string uniqueName)
 {
     if (ComponentRegistry.ContainsKey(uniqueName))
     {
         ComponentRegistry.Remove(uniqueName);
     }
 }
Пример #5
0
        /// <summary>
        /// Registers a component in the component catalog.
        /// </summary>
        /// <typeparam name="I">Interface type of the component</typeparam>
        /// <typeparam name="T">Implementation type of the component</typeparam>
        /// <param name="uniqueName">Unique component name</param>
        /// <param name="activationType">Activation type (SingleCall/Singleton)</param>
        /// <param name="cleanUpHandler">Delegate for external clean up method</param>
        public void RegisterComponent <I, T>(string uniqueName, ActivationType activationType, Action <object> cleanUpHandler)
        {
            Type interfaceType      = typeof(I);
            Type implementationType = typeof(T);

            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_TypeIsNotAInterface, "interfaceType");
            }

            if (!implementationType.IsClass)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_TypeIsNotAClass, "interfaceType");
            }

            new TypeComparer <I, T>().Validate();

            if (string.IsNullOrEmpty(uniqueName))
            {
                uniqueName = interfaceType.FullName;
            }

            // register the component and its queryable methods
            var registration = new ComponentRegistration(interfaceType, implementationType, uniqueName, activationType, cleanUpHandler);

            registration.DisposeWithCatalog = true;
            ComponentRegistry.Register(uniqueName, registration, ZyanSettings.LegacyIgnoreDuplicateRegistrations);

            RegisterQueryableMethods <I>(uniqueName);
        }
Пример #6
0
        /// <summary>
        /// Gets registration data for a specified component by its interface name.
        /// </summary>
        /// <param name="interfaceName">Name of the component´s interface</param>
        /// <returns>Component registration</returns>
        public ComponentRegistration GetRegistration(string interfaceName)
        {
            if (!ComponentRegistry.ContainsKey(interfaceName))
            {
                throw new KeyNotFoundException(string.Format(LanguageResource.KeyNotFoundException_CannotFindComponentForInterface, interfaceName));
            }

            return(ComponentRegistry[interfaceName]);
        }
Пример #7
0
        /// <summary>
        /// Gets registration data for a specified component by its interface name.
        /// </summary>
        /// <param name="interfaceName">Name of the component´s interface</param>
        /// <returns>Component registration</returns>
        public ComponentRegistration GetRegistration(string interfaceName)
        {
            ComponentRegistration registration;

            if (!ComponentRegistry.TryGetRegistration(interfaceName, out registration))
            {
                throw new KeyNotFoundException(string.Format(LanguageResource.KeyNotFoundException_CannotFindComponentForInterface, interfaceName));
            }

            return(registration);
        }
        /// <summary>
        /// Ruft eine bestimmte Komponentenregistrierung ab.
        /// </summary>
        /// <param name="interfaceName">Schnittstellenname</param>
        /// <returns>Komponentenregistrierung</returns>
        public ComponentRegistration GetRegistration(string interfaceName)
        {
            // Wenn für den angegebenen Schnittstellennamen keine Komponente registriert ist ...
            if (!ComponentRegistry.ContainsKey(interfaceName))
            {
                // Ausnahme werfen
                throw new KeyNotFoundException(string.Format("Für die angegebene Schnittstelle '{0}' ist keine Komponente registiert.", interfaceName));
            }

            // Komponentenregistrierung abrufen
            return(ComponentRegistry[interfaceName]);
        }
Пример #9
0
 /// <summary>
 /// Determines whether the specified interface name is registered.
 /// </summary>
 /// <param name="interfaceName">Name of the interface.</param>
 public bool IsRegistered(string interfaceName)
 {
     return(ComponentRegistry.IsRegistered(interfaceName));
 }
Пример #10
0
 /// <summary>
 /// Deletes a component registration.
 /// </summary>
 /// <param name="uniqueName">Unique component name</param>
 public void UnregisterComponent(string uniqueName)
 {
     ComponentRegistry.Remove(uniqueName);
 }