Exemplo n.º 1
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Returns an <see cref="IDatabaseAssembler"/> that represents the building process for a a concrete <see cref="Database"/>.
        /// </summary>
        /// <param name="type">The concrete <see cref="Database"/> type.</param>
        /// <param name="name">The name of the instance to build, or <see langword="null"/> (<b>Nothing</b> in Visual Basic).</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>The <see cref="IDatabaseAssembler"/> instance.</returns>
        /// <exception cref="InvalidOperationException">when concrete <see cref="Database"/> type does have the required <see cref="DatabaseAssemblerAttribute"/>.</exception>
        public IDatabaseAssembler GetAssembler(Type type, string name, ConfigurationReflectionCache reflectionCache)
        {
            bool exists = false;
            IDatabaseAssembler assembler;

            lock (assemblersMappingLock)
            {
                exists = assemblersMapping.TryGetValue(type, out assembler);
            }
            if (!exists)
            {
                DatabaseAssemblerAttribute assemblerAttribute
                    = reflectionCache.GetCustomAttribute <DatabaseAssemblerAttribute>(type);
                if (assemblerAttribute == null)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.Culture,
                                  Resources.ExceptionDatabaseTypeDoesNotHaveAssemblerAttribute,
                                  type.FullName,
                                  name));
                }

                assembler
                    = (IDatabaseAssembler)Activator.CreateInstance(assemblerAttribute.AssemblerType);

                lock (assemblersMappingLock)
                {
                    assemblersMapping[type] = assembler;
                }
            }

            return(assembler);
        }
Exemplo n.º 2
0
 public void CreationOfAttributeWithCorrectTypeSucceeds()
 {
     DatabaseAssemblerAttribute attribute = new DatabaseAssemblerAttribute(typeof(SqlDatabaseAssembler));
 }