public DataProviderFactory(DatabaseConfig.ProviderMapping mapping)
 {
     DataAccess          = mapping.GetDataAccess();
     ConnectionString    = mapping.ConnectionString;
     ConnectionStringKey = mapping.ConnectionStringKey;
     MappedType          = mapping.GetMappedType();
     MappedAssembly      = mapping.GetAssembly();
 }
        public void RegisterDataProviderFactory(DatabaseConfig.ProviderMapping factoryInfo)
        {
            if (factoryInfo == null)
            {
                throw new ArgumentNullException(nameof(factoryInfo));
            }

            lock (DataProviderSyncLock)
            {
                var type     = factoryInfo.GetMappedType();
                var assembly = factoryInfo.GetAssembly();

                // var providerFactoryType = Type.GetType(factoryInfo.ProviderFactoryType); HAS A PROIBLEM WITH VERSIONING
                var providerFactoryType = assembly.GetTypes().FirstOrDefault(t => t.AssemblyQualifiedName == factoryInfo.ProviderFactoryType);
                if (providerFactoryType == null)
                {
                    providerFactoryType = assembly.GetType(factoryInfo.ProviderFactoryType);
                }
                if (providerFactoryType == null)
                {
                    providerFactoryType = Type.GetType(factoryInfo.ProviderFactoryType);
                }

                if (providerFactoryType == null)
                {
                    throw new Exception("Could not find the type " + factoryInfo.ProviderFactoryType + " as specified in configuration.");
                }

                var providerFactory = (IDataProviderFactory)Activator.CreateInstance(providerFactoryType, factoryInfo);

                if (type != null)
                {
                    TypeProviderFactories[type] = providerFactory;
                }
                else if (assembly != null && providerFactory != null)
                {
                    AssemblyProviderFactories[assembly] = providerFactory;
                }

                EntityFinder.ResetCache();
            }
        }