public static void AddMySql(this IServiceCollection services, MySqlConnectionOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Validate();

            services.AddSingleton <IMySqlConnectionFactory>(new MySqlConnectionFactory(options));

            services.AddSingleton <ILinkRepository, LinkRepository>();
            services.AddSingleton <IRoomRepository, RoomRepository>();
            services.AddSingleton <IRunRepository, RunRepository>();
            services.AddSingleton <IUserRepository, UserRepository>();
            services.AddSingleton <IOrderRepository, OrderRepository>();
            services.AddSingleton <IOptionsRepository, OptionsRepository>();
            services.AddSingleton <ILockRepository, LockRepository>();
            services.AddSingleton <IIllMakeRepository, IllMakeRepository>();

            services.AddSingleton <IIdGenerator <long>, MySqlIdGenerator>();
            services.AddSingleton <IDistributedHash, MySqlDistributedHash>();


            services.AddTransient <IStartupAction, MySqlServerVerificationStartupAction>();
        }
        public MySqlConnectionFactory(MySqlConnectionOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _connectionString = GetConnectionString(options);
        }
        private static string GetConnectionString(MySqlConnectionOptions options)
        {
            string GetOption(string key, string value)
            => string.IsNullOrWhiteSpace(value) ? string.Empty : key + "=" + value + ";";

            return(string.Concat(
                       GetOption("host", options.Host),
                       GetOption("port", options.Port.ToString()),
                       GetOption("username", options.Username),
                       GetOption("password", options.Password),
                       GetOption("database", options.Database),
                       "UseAffectedRows=true"
                       ));
        }