From 9e9281b20d1170ee91764c1bb0aa45169a642367 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 12 Oct 2022 12:36:22 -0700 Subject: Demo DynamicEndpointDataSource --- .../samples/MinimalSample/DynamicEndpointDataSource.cs | 2 +- src/Http/samples/MinimalSample/Program.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Http/samples/MinimalSample/DynamicEndpointDataSource.cs b/src/Http/samples/MinimalSample/DynamicEndpointDataSource.cs index 678edd43e0..133cf771f9 100644 --- a/src/Http/samples/MinimalSample/DynamicEndpointDataSource.cs +++ b/src/Http/samples/MinimalSample/DynamicEndpointDataSource.cs @@ -16,7 +16,7 @@ public sealed class DynamicEndpointDataSource : EndpointDataSource, IDisposable public DynamicEndpointDataSource() { - _timer = new PeriodicTimer(TimeSpan.FromSeconds(5)); + _timer = new PeriodicTimer(TimeSpan.FromSeconds(1)); _timerTask = TimerLoop(); } diff --git a/src/Http/samples/MinimalSample/Program.cs b/src/Http/samples/MinimalSample/Program.cs index 5155875e45..9817b44c1e 100644 --- a/src/Http/samples/MinimalSample/Program.cs +++ b/src/Http/samples/MinimalSample/Program.cs @@ -6,6 +6,7 @@ using System.Text; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Primitives; +using MinimalSample; var builder = WebApplication.CreateBuilder(args); @@ -13,8 +14,11 @@ builder.Services.AddControllers(); var app = builder.Build(); -app.MapGet("/", (EndpointDataSource dataSource) - => EndpointDataSource.GetDebuggerDisplayStringForEndpoints(dataSource.Endpoints)); +app.MapGet("/", (EndpointDataSource dataSource, HttpResponse response) => +{ + response.Headers["Refresh"] = "1"; + return EndpointDataSource.GetDebuggerDisplayStringForEndpoints(dataSource.Endpoints); +}); var preview = app.MapGroup("/preview"); AddEndpoints(app); @@ -61,6 +65,8 @@ static void AddEndpoints(IEndpointRouteBuilder app) app.MapGet("/hello/{name}", (string name) => $"Hello {name}!") .AddEndpointFilterFactory((context, next) => { + Console.WriteLine("Running filter factory!"); + var parameters = context.MethodInfo.GetParameters(); // Only operate handlers with a single argument if (parameters.Length == 1 && @@ -91,7 +97,8 @@ static void AddEndpoints(IEndpointRouteBuilder app) return next(invocationContext); }); - app.DataSources.Add(new CustomEndpointDataSource()); + app.DataSources.Add(new DefaultEndpointDataSource(CustomEndpointDataSource.CreateEndpoint(0), CustomEndpointDataSource.CreateEndpoint(1))); + app.DataSources.Add(new DynamicEndpointDataSource()); } class CustomEndpointDataSource : EndpointDataSource @@ -104,7 +111,7 @@ class CustomEndpointDataSource : EndpointDataSource public override IChangeToken GetChangeToken() => NullChangeToken.Singleton; - static Endpoint CreateEndpoint(int id) + public static Endpoint CreateEndpoint(int id) { var displayName = $"Custom endpoint #{id}"; var metadata = new EndpointMetadataCollection(new[] { new RouteNameMetadata(displayName) }); -- cgit v1.2.3