Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.Configure <CommandHandlerSettings>(Configuration.GetSection("CommandHandlerSettings"));
            services.Configure <TwitchClientSettings>(Configuration.GetSection("TwitchClientSettings"));
            services.Configure <GoogleCloudSettings>(Configuration.GetSection("GoogleCloudSettings"));

            services.AddDbContext <AppDataContext>(ServiceLifetime.Transient);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSignalR();

            var builder = new ContainerBuilder();

            builder.Populate(services);

            var assemblies = new[]
            {
                Assembly.GetAssembly(typeof(IRepository)),
                Assembly.GetAssembly(typeof(EfGenericRepo)),
                Assembly.GetAssembly(typeof(GoogleApiTimezoneLookup)),
                Assembly.GetAssembly(typeof(TwitchChatClient)),
                Assembly.GetAssembly(typeof(BotHub)),
                Assembly.GetAssembly(typeof(Program)),
            };

            foreach (var assembly in assemblies)
            {
                builder.RegisterAssemblyTypes(assembly)
                .AssignableTo <BaseCommand>()
                .As <IBotCommand>()
                .SingleInstance();
            }

            // register types here
            var fullConfig = Configuration.Get <BotConfiguration>();

            builder.RegisterInstance(fullConfig.TwitchClientSettings)
            .As <TwitchClientSettings>().SingleInstance();

            builder.RegisterInstance(fullConfig.CommandHandlerSettings)
            .AsSelf().SingleInstance();

            builder.RegisterInstance(fullConfig.GoogleCloudSettings)
            .AsSelf().SingleInstance();


            IRepository repository = SetUpDatabase.SetUpRepository(fullConfig.DatabaseConnectionString);

            builder.RegisterInstance(repository).SingleInstance();

            RegisterTimezoneLookupClasses(builder);

            builder.RegisterGeneric(typeof(Logger <>))
            .As(typeof(ILogger <>)).SingleInstance();

            builder.RegisterGeneric(typeof(LoggerAdapter <>))
            .As(typeof(ILoggerAdapter <>)).SingleInstance();

            builder.RegisterGeneric(typeof(List <>))
            .As(typeof(IList <>)).SingleInstance();

            builder.RegisterGeneric(typeof(Lazier <>))
            .As(typeof(Lazy <>)).InstancePerRequest();

            builder.RegisterType <AutomationSystem>()
            .As <IAutomatedActionSystem>().SingleInstance();
            builder.RegisterType <CommandHandler>()
            .As <ICommandHandler>().SingleInstance();

            builder.RegisterType <ChatUserCollection>()
            .As <IChatUserCollection>()
            .SingleInstance();

            builder.RegisterType <SettingsFactory>()
            .As <ISettingsFactory>();

            builder.RegisterType <CommandCooldownTracker>()
            .As <ICommandUsageTracker>();

            builder.RegisterType <SystemClock>()
            .As <IClock>();

            builder.RegisterType <StreamingSystem>()
            .AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <AnimationDisplayNotification>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <HangmanDisplayNotification>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <VotingDisplayNotification>()
            .AsImplementedInterfaces().SingleInstance();

            builder.AddAllGames();

            builder.AddSimpleCommandsFromRepository(repository);

            builder.AddCommandSystem();

            builder.Register(p =>
                             new CommandList(p.Resolve <IList <IBotCommand> >().ToList(), p));

            builder.RegisterModule <CoreRegistrationModule>();

            builder.RegisterModule(new TwitchModule(fullConfig.TwitchClientSettings));

            builder.RegisterType <AutomationSystem>()
            .As <IAutomatedActionSystem>().SingleInstance();

            builder.RegisterType <BotMain>().AsSelf().SingleInstance();

            builder.RegisterType <DevChatterBotBackgroundWorker>()
            .As <IHostedService>();

            builder.RegisterModule(new AutomatedMessageModule(repository));
            builder.RegisterModule <CurrencyModule>();

            ApplicationContainer = builder.Build();

            return(new AutofacServiceProvider(ApplicationContainer));
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.Configure <CommandHandlerSettings>(Configuration.GetSection("CommandHandlerSettings"));
            services.Configure <TwitchClientSettings>(Configuration.GetSection("TwitchClientSettings"));
            services.Configure <GoogleCloudSettings>(Configuration.GetSection("GoogleCloudSettings"));

            var fullConfig = Configuration.Get <BotConfiguration>();

            services.AddSingleton(fullConfig.TwitchClientSettings);
            services.AddSingleton(fullConfig.CommandHandlerSettings);
            services.AddSingleton(fullConfig.GoogleCloudSettings);

            services.Configure <BotConfiguration>(Configuration);

            services.AddSingleton <ILoggerFactory, LoggerFactory>();

            IRepository repository = SetUpDatabase.SetUpRepository(fullConfig.DatabaseConnectionString);

            services.AddSingleton(repository);

            RegisterTimezoneLookupClasses(services);

            services.AddSingleton <IStreamingPlatform, StreamingPlatform>();
            services.AddSingleton <IClock, SystemClock>();

            services.AddSingleton(typeof(ILogger <>), typeof(Logger <>));
            services.AddSingleton(typeof(ILoggerAdapter <>), typeof(LoggerAdapter <>));
            services.AddSingleton <ISettingsFactory, SettingsFactory>();

            services.AddSingleton <IChatUserCollection, ChatUserCollection>();

            services.AddSingleton(typeof(IList <>), typeof(List <>));
            services.AddTransient(typeof(Lazy <>), typeof(Lazier <>));

            services.AddAllGames();

            services.AddStreamMetaCommands();

            services.AddCurrencySystem();

            services.AddSimpleCommandsFromRepository(repository);

            services.AddCommandSystem();

            services.AddTwitchLibConnection(fullConfig.TwitchClientSettings);

            services.AddSingleton <IAutomatedActionSystem, AutomationSystem>();

            services.AddSingleton <BotMain>();

            services.AddSingleton <IHostedService, DevChatterBotBackgroundWorker>();

            services.AddDbContext <AppDataContext>(ServiceLifetime.Transient);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSignalR();
        }