/// <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); }
/// <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); }