public static void Init()
        {
            LogHelper.LogApp($"{MethodBase.GetCurrentMethod().Name}");

            if (File.Exists(ConfigPath))
            {
                string _json = File.ReadAllText(ConfigPath);
                _Config = JsonConvert.DeserializeObject <DBConnectionConfig>(_json);

                if (!string.IsNullOrWhiteSpace(_Config.Server) && !string.IsNullOrWhiteSpace(_Config.Database))
                {
                    _ConnectionString =
                        $"Data Source={_Config.Server};" +
                        $"Initial Catalog={_Config.Database};" +
                        "Integrated Security=True;" +
                        "MultipleActiveResultSets=True;";

                    _Connection = new SqlConnection(_ConnectionString);

                    _Connection.Open();
                }
                else
                {
                    throw new FormatException($"Config values from '{ConfigPath}' are corrupted or empty!");
                }
            }
            else
            {
                throw new FileNotFoundException("Database connection configuration file not found!", ConfigPath);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 使用SqlServer
        /// </summary>
        /// <param name="services"></param>
        /// <param name="setConfig"></param>
        public static IServiceCollection AddSqlServer(this IServiceCollection services, string connectionString)
        {
            var dbConfig = new DBConnectionConfig(DBType.SqlServer)
            {
                ConnectionString = connectionString
            };

            services.AddSingleton(dbConfig);

            services.AddSingleton <ILayIMStorage, LayIMDapperStorage>();

            RegisterRepositories(services);

            return(services);
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var dbConnConfig = new DBConnectionConfig();

            Configuration.Bind("DatabaseSettings", dbConnConfig);

            services.AddSingleton(dbConnConfig);

            services.AddSingleton <IConnectionProvider, ConnectionProvider>();
            services.AddSingleton <IUserProcessor, UserProcessor>();
            services.AddSingleton <IUserProvider, UserProvider>();
            services.AddSingleton <ITokenProvider, TokenProvider>();
        }
 public ChatRecordRepository(DBConnectionConfig config) : base(config)
 {
 }
Beispiel #5
0
 public BigGroupRepository(DBConnectionConfig dbConfig) : base(dbConfig)
 {
 }
 public GroupMemberRepository(DBConnectionConfig dbConfig) : base(dbConfig)
 {
 }
 public FriendRelationRepository(DBConnectionConfig dbConfig) : base(dbConfig)
 {
 }
 public LoginController(IConnectionProvider con, IUserProcessor upcr, IUserProvider updr, ITokenProvider token, DBConnectionConfig config)
 {
     this.con   = con;
     this.upcr  = upcr;
     this.updr  = updr;
     this.token = token;
     conStr     = config.MyConnectionString;
 }
Beispiel #9
0
 ///// <summary>
 ///// 有参构造
 ///// </summary>
 ///// <param name="config"></param>
 //public DapperClient(IOptionsMonitor<ConnectionConfig> config)
 //{
 //    CurrentConnectionConfig = config.CurrentValue;
 //}
 /// <summary>
 /// 有参构造
 /// </summary>
 /// <param name="config"></param>
 public DapperClient(DBConnectionConfig config)
 {
     CurrentConnectionConfig = config;
 }
 public UserRepository(DBConnectionConfig dbConfig) : base(dbConfig)
 {
 }
 public BaseRepository(DBConnectionConfig dbConfig)
 {
     this.dbConfig = dbConfig;
 }
 public FriendGroupRepository(DBConnectionConfig dbConfig) : base(dbConfig)
 {
 }