private static void RegisterFaucet(IServiceCollection services,
                                    IFaucetConfiguration faucetConfiguration,
                                    IFaucetBalanceConfiguration faucetBalanceConfiguration,
                                    IHouseBalanceConfiguration houseAlerterConfiguration)
 {
     services.AddSingleton <IFaucetManager, FaucetManager>();
     services.AddSingleton(faucetConfiguration);
     services.AddSingleton(faucetBalanceConfiguration);
     services.AddSingleton(houseAlerterConfiguration);
 }
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="houseAccountAlerter">House account alerter</param>
        /// <param name="houseBalanceConfiguration">House balance configuration</param>
        public LowBalanceWatcher(IHouseAccountAlerter houseAccountAlerter, IHouseBalanceConfiguration houseBalanceConfiguration)
        {
            if (houseAccountAlerter == null)
            {
                throw new ArgumentNullException(nameof(houseAccountAlerter));
            }

            this._houseBalanceConfiguration = houseBalanceConfiguration ?? throw new ArgumentNullException(nameof(houseBalanceConfiguration));
            this._houseAccounts             = new ConcurrentDictionary <NetworkAccount, bool>();

            this._subscription = Observable.FromEventPattern <EthereumBalanceChangeEventArgs>(addHandler: h => houseAccountAlerter.OnEthereumBalanceChanged += h,
                                                                                              removeHandler: h => houseAccountAlerter.OnEthereumBalanceChanged -= h)
                                 .Select(e => e.EventArgs)
                                 .Subscribe(e => this.UpdateBalanceStatus((NetworkAccount)e.Account, ethereumAmount: e.NewBalance));
        }
        /// <summary>
        ///     Configures the Server logic
        /// </summary>
        /// <param name="services">The services collection to register services in.</param>
        /// <param name="faucetConfiguration">Faucet configuration</param>
        /// <param name="faucetBalanceConfiguration">Faucet balance configuration</param>
        /// <param name="houseAlerterConfiguration">House alerter configuration</param>
        public static void Configure(IServiceCollection services,
                                     IFaucetConfiguration faucetConfiguration,
                                     IFaucetBalanceConfiguration faucetBalanceConfiguration,
                                     IHouseBalanceConfiguration houseAlerterConfiguration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            RegisterBalances(services);
            RegisterPlayers(services);
            RegisterFaucet(services: services, faucetConfiguration: faucetConfiguration, faucetBalanceConfiguration: faucetBalanceConfiguration, houseAlerterConfiguration: houseAlerterConfiguration);
            RegisterGames(services);
        }
        /// <summary>
        ///     Configures the Ethereum Contracts
        /// </summary>
        /// <param name="services">The services collection to register services in.</param>
        /// <param name="faucetConfiguration">Faucet configuration</param>
        /// <param name="faucetBalanceConfiguration">Faucet balance configuration</param>
        /// <param name="houseAlerterConfiguration">House alerter configuration</param>
        public static void Configure(IServiceCollection services,
                                     IFaucetConfiguration faucetConfiguration,
                                     IFaucetBalanceConfiguration faucetBalanceConfiguration,
                                     IHouseBalanceConfiguration houseAlerterConfiguration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton <IDrainedFaucetAlerter, DrainedFaucetAlerter>();
            services.AddSingleton <IHouseAccountAlerter, HouseAccountAlerter>();
            services.AddHostedSingletonService <ILowBalanceWatcherService, LowBalanceWatcherService>();

            RegisterPlayers(services);
            RegisterFaucet(services: services, faucetConfiguration: faucetConfiguration, faucetBalanceConfiguration: faucetBalanceConfiguration, houseAlerterConfiguration: houseAlerterConfiguration);
        }