示例#1
0
        private Program([NotNull] Configuration config)
        {
            _config = config;

            _commands = new CommandService(new CommandServiceConfig {
                CaseSensitiveCommands = false,
                DefaultRunMode        = RunMode.Async,
                ThrowOnError          = true
            });
            _client = new DiscordSocketClient();

            var kernel = new StandardKernel();

            _services = kernel;

            kernel.Bind <Random>().To <Random>().InTransientScope();
            kernel.Bind <IHttpClient>().To <MuteHttpClient>().InTransientScope();

            kernel.Bind <IServiceProvider>().ToConstant(kernel);
            kernel.Bind <Configuration>().ToConstant(_config);
            kernel.Bind <CommandService>().ToConstant(_commands);
            kernel.Bind <DiscordSocketClient>().ToConstant(_client);
            kernel.Bind <IDiscordClient>().ToConstant(_client);

            kernel.Bind <IDatabaseService>().To <DatabaseService>().InSingletonScope();
            kernel.Bind <ISentimentService>().To <TensorflowSentimentService>().InSingletonScope();
            kernel.Bind <InteractiveService>().ToConstructor(a => new InteractiveService(a.Inject <DiscordSocketClient>(), null)).InSingletonScope();

            kernel
            .AddSingleton <CatPictureService>()
            .AddSingleton <DogPictureService>()
            .AddSingleton <CryptoCurrencyService>()
            .AddSingleton <AlphaAdvantageService>()
            .AddSingleton <IouDatabaseService>()
            .AddSingleton <MusicPlayerService>()
            .AddSingleton <YoutubeService>()
            .AddSingleton <MusicRatingService>()
            .AddSingleton <GameService>()
            .AddSingleton <ReminderService>()
            .AddSingleton <SentimentTrainingService>()
            .AddSingleton <HistoryLoggingService>()
            .AddSingleton <ReactionSentimentTrainer>()
            .AddSingleton <ConversationalResponseService>()
            .AddSingleton <WikipediaService>()
            .AddSingleton <TimeService>()
            .AddSingleton <SteamApi>()
            .AddSingleton <SoundEffectService>()
            .AddSingleton <WordsService>()
            .AddSingleton <SpacexService>()
            .AddSingleton <WordVectorsService>()
            .AddSingleton <UptimeService>()
            .AddSingleton <WordTrainingService>()
            .AddSingleton <RoleService>()
            .AddSingleton <MultichannelAudioService>();

            //Find all types which implement IPreloadService and load them
            var preload = Assembly
                          .GetExecutingAssembly()
                          .GetTypes()
                          .Where(t => t.IsClass && !t.IsAbstract)
                          .Where(t => typeof(IPreloadService).IsAssignableFrom(t))
                          .Select(t => (IPreloadService)kernel.Get(t))
                          .ToArray();

            Console.WriteLine("Preloading Services:");
            foreach (var preloadService in preload)
            {
                Console.WriteLine($" - {preloadService.GetType().Name}");
            }
        }