public static bool InitPostgreSQL(this Funq.Container container)
        {
            try
            {
                // Register the PostgreSQL Database Connection Factory
                var postgreSqlConnectionString = ConfigurationManager.ConnectionStrings["PostgreSQL"];
                var postgreSqlFactory = new PostgreSqlOrmLiteConnectionFactory(postgreSqlConnectionString.ConnectionString);
                postgreSqlFactory.DialectProvider.UseUnicode = true;
                container.Register<IPostgreSqlOrmLiteConnectionFactory>(c => postgreSqlFactory);

                // Create needed tables in PostgreSql Server if they do not exist
                using (var conn = postgreSqlFactory.OpenDbConnection())
                {
                    return conn.CreateWorldTable() && conn.CreateFortuneTable();
                }
            }
            catch (Exception ex)
            {
                // Unregister failed database connection factory
                container.Register<IPostgreSqlOrmLiteConnectionFactory>(c => null);

                return false;
            }

        }
示例#2
0
        private static void InitDatabases(Funq.Container container)
        {
            // Register the MySql Database Connection Factory
            var mySqlFactory = new MySqlOrmLiteConnectionFactory(mySqlConnectionString.ConnectionString);

            mySqlFactory.DialectProvider.UseUnicode = true;
            container.Register <IMySqlOrmLiteConnectionFactory>(c => mySqlFactory);

            // Create needed tables in MySql Server if they do not exist
            try
            {
                using (var conn = mySqlFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }

            // Register the PostgreSQL Database Connection Factory
            var postgreSqlFactory = new PostgreSqlOrmLiteConnectionFactory(postgreSqlConnectionString.ConnectionString);

            postgreSqlFactory.DialectProvider.UseUnicode = true;
            container.Register <IPostgreSqlOrmLiteConnectionFactory>(c => postgreSqlFactory);

            // Create needed tables in PostgreSql Server if they do not exist
            try
            {
                using (var conn = postgreSqlFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }

            // Register the Microsoft Sql Server Database Connection Factory
            var sqlServerFactory = new SqlServerOrmLiteConnectionFactory(sqlServerConnectionString.ConnectionString);

            sqlServerFactory.DialectProvider.UseUnicode = true;
            container.Register <ISqlServerOrmLiteConnectionFactory>(c => sqlServerFactory);

            // Create needed tables in Microsoft Sql Server if they do not exist
            try
            {
                using (var conn = sqlServerFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }
        }
示例#3
0
        public static bool InitPostgreSQL(this Funq.Container container)
        {
            try
            {
                // Register the PostgreSQL Database Connection Factory
                var postgreSqlConnectionString = ConfigurationManager.ConnectionStrings["PostgreSQL"];
                var postgreSqlFactory          = new PostgreSqlOrmLiteConnectionFactory(postgreSqlConnectionString.ConnectionString);
                postgreSqlFactory.DialectProvider.UseUnicode = true;
                container.Register <IPostgreSqlOrmLiteConnectionFactory>(c => postgreSqlFactory);

                // Create needed tables in PostgreSql Server if they do not exist
                using (var conn = postgreSqlFactory.OpenDbConnection())
                {
                    return(conn.CreateWorldTable() && conn.CreateFortuneTable());
                }
            }
            catch (Exception ex)
            {
                // Unregister failed database connection factory
                container.Register <IPostgreSqlOrmLiteConnectionFactory>(c => null);

                return(false);
            }
        }
示例#4
0
        private static void InitDatabases(Funq.Container container)
        {
            // Register the MySql Database Connection Factory
            var mySqlFactory = new MySqlOrmLiteConnectionFactory(mySqlConnectionString.ConnectionString);
            mySqlFactory.DialectProvider.UseUnicode = true;
            container.Register<IMySqlOrmLiteConnectionFactory>(c => mySqlFactory);

            // Create needed tables in MySql Server if they do not exist
            try
            {
                using (var conn = mySqlFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }

            // Register the PostgreSQL Database Connection Factory
            var postgreSqlFactory = new PostgreSqlOrmLiteConnectionFactory(postgreSqlConnectionString.ConnectionString);
            postgreSqlFactory.DialectProvider.UseUnicode = true;
            container.Register<IPostgreSqlOrmLiteConnectionFactory>(c => postgreSqlFactory);

            // Create needed tables in PostgreSql Server if they do not exist
            try
            {
                using (var conn = postgreSqlFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }

            // Register the Microsoft Sql Server Database Connection Factory
            var sqlServerFactory = new SqlServerOrmLiteConnectionFactory(sqlServerConnectionString.ConnectionString);
            sqlServerFactory.DialectProvider.UseUnicode = true;
            container.Register<ISqlServerOrmLiteConnectionFactory>(c => sqlServerFactory);

            // Create needed tables in Microsoft Sql Server if they do not exist
            try
            {
                using (var conn = sqlServerFactory.OpenDbConnection())
                {
                    conn.CreateWorldTable();
                    conn.CreateFortuneTable();
                }
            }
            catch
            { }
        }