예제 #1
0
        /// <summary>
        /// Gets a universal context
        /// </summary>
        /// <param name="dbsettings">the database settings</param>
        /// <returns>IUniversalContext</returns>
        public IUniversalContext CreateContext(IDbSettings dbsettings)
        {
            ProviderType provider = dbsettings.Provider;

            switch (provider)
            {
            case ProviderType.MySQL:
                return(new MySqlContext(dbsettings));

            case ProviderType.SQLite:
                return(new SqLiteContext(dbsettings));

            default:
                // Get all classes from DbContexts namespace
                List <Type> listTypeDbClasses = GenericUtils.AllClassesFromNamespace(Nsp);

                // Get the class type to instantiate
                var clazz = GenericUtils.GetClassesFromProperty(listTypeDbClasses, "Provider", provider);
                return((IUniversalContext)Activator.CreateInstance(clazz, dbsettings));
            }
        }