From e3b1a32535698f78ae094f7d6e4b863772168fb9 Mon Sep 17 00:00:00 2001 From: Florian Zevedei Date: Fri, 29 Sep 2023 18:40:20 +0200 Subject: [PATCH] Adding missing Program.cs --- Examples/DependencyInjection/Program.cs | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Examples/DependencyInjection/Program.cs diff --git a/Examples/DependencyInjection/Program.cs b/Examples/DependencyInjection/Program.cs new file mode 100644 index 0000000..f33bf53 --- /dev/null +++ b/Examples/DependencyInjection/Program.cs @@ -0,0 +1,35 @@ +using DependencyInjection.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using TelegramBotBase.Builder; + +namespace DependencyInjection +{ + internal class Program + { + static async Task Main(string[] args) + { + + + var serviceCollection = new ServiceCollection() + .AddDbContext(x => x.UseInMemoryDatabase("TelegramBotBase")); + + var serviceProvider = serviceCollection.BuildServiceProvider(); + + var bot = BotBaseBuilder.Create() + .WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ?? + throw new Exception("API_KEY is not set")) + .DefaultMessageLoop() + .WithServiceProvider(serviceProvider) + .NoProxy() + .NoCommands() + .NoSerialization() + .DefaultLanguage() + .Build(); + + await bot.Start(); + await Task.Delay(-1); + + } + } +} \ No newline at end of file