static private IServiceProvider Initialize() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true) .AddUserSecrets <Program>() .Build(); var twitchSettings = new TwitchAdapterSettings(); config.GetSection("twitchBot").Bind(twitchSettings); var services = new ServiceCollection() .AddSingleton <IConfiguration>(p => config) .AddLogging(loggin => { loggin.SetMinimumLevel(LogLevel.Trace); loggin.AddConsole(); loggin.AddDebug(); }) .AddTransient <IBot, TwitchBot>() .AddSingleton <TwitchAdapter>(sp => new TwitchAdapter(sp, twitchSettings)); services.Configure <TwitchAdapterSettings>(config.GetSection("twitchBot")); return(services.BuildServiceProvider()); }
public static IHostBuilder CreateHostBuilder(string[] args) { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true) .AddUserSecrets <Program>() .Build(); var twitchSettings = new TwitchAdapterSettings(); config.GetSection("twitchBot").Bind(twitchSettings); return(Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.AddTransient <IBot, TwitchBot>() .AddTwitchBotAdapter(twitchSettings); })); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) services.AddSingleton <IStorage, MemoryStorage>(); // Create the User state. services.AddSingleton <UserState>(); BotCommandManager cmdMgr = SetUpCommands(); services.AddSingleton <BotCommandManager>(cmdMgr); services.AddSingleton <CommandTypeManager>(); services.AddTransient <IBot, SampleTwitchBot>(); var twitchSettings = new TwitchAdapterSettings(); Configuration.GetSection("twitchBot").Bind(twitchSettings); services.AddTwitchBotAdapter(twitchSettings); }
public static IServiceCollection AddTwitchBotAdapter(this IServiceCollection services, TwitchAdapterSettings settings) { services.AddSingleton <TwitchAdapter>(sp => new TwitchAdapter(sp, settings)) .AddHostedService <TwitchBotWorker>(); return(services); }