diff options
author | Stephen Halter <halter73@gmail.com> | 2022-10-12 22:36:22 +0300 |
---|---|---|
committer | Stephen Halter <halter73@gmail.com> | 2022-10-12 22:36:22 +0300 |
commit | 9e9281b20d1170ee91764c1bb0aa45169a642367 (patch) | |
tree | 2997bac68b6aa3c43e363a9b62fda9574eafedbb | |
parent | 3d17094f82dc971e65196d7c807f072c003fcaf2 (diff) |
Demo DynamicEndpointDataSourceignite-demo-update
-rw-r--r-- | src/Http/samples/MinimalSample/DynamicEndpointDataSource.cs | 2 | ||||
-rw-r--r-- | 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) }); |