コード例 #1
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
            { }
        }
コード例 #2
0
        public static bool InitSQLServer(this Funq.Container container)
        {
            try
            {
                // Register the Microsoft Sql Server Database Connection Factory
                var sqlServerConnectionString = ConfigurationManager.ConnectionStrings["SQLServer"];
                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
                using (var conn = sqlServerFactory.OpenDbConnection())
                {
                    return(conn.CreateWorldTable() && conn.CreateFortuneTable());
                }
            }
            catch (Exception ex)
            {
                // Unregister failed database connection factory
                container.Register <ISqlServerOrmLiteConnectionFactory>(c => null);

                return(false);
            }
        }
コード例 #3
0
        public static bool InitSQLServer(this Funq.Container container)
        {
            try
            {
                // Register the Microsoft Sql Server Database Connection Factory
                var sqlServerConnectionString = ConfigurationManager.ConnectionStrings["SQLServer"];
                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
                using (var conn = sqlServerFactory.OpenDbConnection())
                {
                    return conn.CreateWorldTable() && conn.CreateFortuneTable();
                }
            }
            catch (Exception ex)
            {
                // Unregister failed database connection factory
                container.Register<ISqlServerOrmLiteConnectionFactory>(c => null);

                return false;
            }

        }
コード例 #4
0
ファイル: AppHost.cs プロジェクト: Geroo/FrameworkBenchmarks
        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
            { }
        }