Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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]);
        }
Ejemplo n.º 5
0
        /// <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]);
        }