From 614ffee6c27ac4ca524bd11c2f63fc2705947c26 Mon Sep 17 00:00:00 2001 From: AoshiW Date: Fri, 3 May 2024 15:56:47 +0200 Subject: [PATCH] update example to .NET 8 --- README.md | 6 ++- .../Program.cs | 45 +++++++++++------ .../Startup.cs | 50 ------------------- ...TwitchLib.EventSub.Webhooks.Example.csproj | 4 +- 4 files changed, 35 insertions(+), 70 deletions(-) delete mode 100644 TwitchLib.EventSub.Webhooks.Example/Startup.cs diff --git a/README.md b/README.md index e7497c9..0681dcd 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The usual requirements that Twitch has for EventSub webhooks do still apply! ## Setup -Step 1: Create a new ASP.NET Core project (.NET 5.0 and up) +Step 1: Create a new ASP.NET Core project (.NET 6.0 and up) Step 2: Install the TwitchLib.EventSub.Webhooks nuget package. (See above on how to do that) @@ -54,7 +54,8 @@ public void ConfigureServices(IServiceCollection services) } ``` -!!! If you follow these steps your callback url will https://{your_domain}/webhooks !!! +!!! If you follow these steps your callback url will `https://{your_domain}/webhooks`!!! +(The location of where to put this and the naming of variables might differ depending on what kind of project and general setup you have) Step 4: Put the TwitchLib.EventSub.Webhooks middleware in the request pipeline @@ -78,6 +79,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) }); } ``` +(The location of where to put this and the naming of variables might differ depending on what kind of project and general setup you have) Step 5: Create the HostedService and listen for events diff --git a/TwitchLib.EventSub.Webhooks.Example/Program.cs b/TwitchLib.EventSub.Webhooks.Example/Program.cs index 8c9dd92..9390807 100644 --- a/TwitchLib.EventSub.Webhooks.Example/Program.cs +++ b/TwitchLib.EventSub.Webhooks.Example/Program.cs @@ -1,20 +1,33 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using TwitchLib.EventSub.Webhooks.Example; +using TwitchLib.EventSub.Webhooks.Extensions; -namespace TwitchLib.EventSub.Webhooks.Example +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddControllers(); +builder.Services.AddTwitchLibEventSubWebhooks(config => +{ + config.CallbackPath = "/webhooks"; + config.Secret = "supersecuresecret"; +}); +builder.Services.AddHostedService(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseDeveloperExceptionPage(); } + +app.UseRouting(); +app.UseAuthorization(); + +app.UseTwitchLibEventSubWebhooks(); + +app.MapControllers(); + +app.Run(); diff --git a/TwitchLib.EventSub.Webhooks.Example/Startup.cs b/TwitchLib.EventSub.Webhooks.Example/Startup.cs deleted file mode 100644 index dbc8627..0000000 --- a/TwitchLib.EventSub.Webhooks.Example/Startup.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using TwitchLib.EventSub.Webhooks.Extensions; - -namespace TwitchLib.EventSub.Webhooks.Example -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - services.AddTwitchLibEventSubWebhooks(config => - { - config.CallbackPath = "/webhooks"; - config.Secret = "supersecuresecret"; - }); - - services.AddHostedService(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseTwitchLibEventSubWebhooks(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } -} diff --git a/TwitchLib.EventSub.Webhooks.Example/TwitchLib.EventSub.Webhooks.Example.csproj b/TwitchLib.EventSub.Webhooks.Example/TwitchLib.EventSub.Webhooks.Example.csproj index 26c23db..fe051c9 100644 --- a/TwitchLib.EventSub.Webhooks.Example/TwitchLib.EventSub.Webhooks.Example.csproj +++ b/TwitchLib.EventSub.Webhooks.Example/TwitchLib.EventSub.Webhooks.Example.csproj @@ -1,7 +1,7 @@ - + - net5.0 + net8.0