diff --git a/signalr/hubs/KeyedSvsHub/KeyedSvsHub.csproj b/signalr/hubs/KeyedSvsHub/KeyedSvsHub.csproj new file mode 100644 index 0000000..1b28a01 --- /dev/null +++ b/signalr/hubs/KeyedSvsHub/KeyedSvsHub.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/signalr/hubs/KeyedSvsHub/Program.cs b/signalr/hubs/KeyedSvsHub/Program.cs new file mode 100644 index 0000000..10625a5 --- /dev/null +++ b/signalr/hubs/KeyedSvsHub/Program.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.SignalR; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddKeyedSingleton("big"); +builder.Services.AddKeyedSingleton("small"); + +builder.Services.AddRazorPages(); +builder.Services.AddSignalR(); + +var app = builder.Build(); + +app.MapRazorPages(); +app.MapHub("/myHub"); + +app.Run(); + +public interface ICache +{ + object Get(string key); +} +public class BigCache : ICache +{ + public object Get(string key) => $"Resolving {key} from big cache."; +} + +public class SmallCache : ICache +{ + public object Get(string key) => $"Resolving {key} from small cache."; +} + +public class MyHub : Hub +{ + public void SmallCacheMethod([FromKeyedServices("small")] ICache cache) + { + Console.WriteLine(cache.Get("signalr")); + } + + public void BigCacheMethod([FromKeyedServices("big")] ICache cache) + { + Console.WriteLine(cache.Get("signalr")); + } +} diff --git a/signalr/hubs/KeyedSvsHub/appsettings.json b/signalr/hubs/KeyedSvsHub/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/signalr/hubs/KeyedSvsHub/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}