allow new items to be added to sub menus at runtime, from a config file

This commit is contained in:
TheXamlGuy
2024-01-18 22:28:53 +00:00
parent 78cedcdeb8
commit 2fed876182
8 changed files with 110 additions and 47 deletions
@@ -12,6 +12,8 @@ public static class IServiceCollectionExtensions
public static IServiceCollection AddCache<TKey, TValue>(this IServiceCollection services)
where TKey :
notnull
where TValue :
notnull
{
services.AddScoped<ICache<TKey, TValue>, Cache<TKey, TValue>>();
services.AddTransient(provider => provider.GetService<ICache<TKey, TValue>>()!.Select(x => x.Value));
+9 -3
View File
@@ -30,8 +30,10 @@ public class Cache<TValue>(IDisposer disposer) :
public class Cache<TKey, TValue>(IDisposer disposer) :
ICache<TKey, TValue>
where TKey : notnull
where TValue : notnull
where TKey :
notnull
where TValue :
notnull
{
private readonly ConcurrentDictionary<TKey, TValue> cache = new();
@@ -40,9 +42,13 @@ public class Cache<TKey, TValue>(IDisposer disposer) :
{
cache.TryAdd(key, value);
disposer.Add(value, Disposable.Create(() =>
{
Remove(key);
}));
disposer.Add(key, Disposable.Create(() =>
{
disposer.Dispose(value);
Remove(key);
}));
}
+5 -4
View File
@@ -1,6 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar;
namespace Hyperbar;
public interface ICache<TValue> :
IEnumerable<TValue>
@@ -14,7 +12,10 @@ public interface ICache<TValue> :
public interface ICache<TKey, TValue> :
IEnumerable<KeyValuePair<TKey, TValue>>
where TKey : notnull
where TKey :
notnull
where TValue :
notnull
{
void Add(TKey key,
TValue value);
+12
View File
@@ -10,3 +10,15 @@ public interface IFactory<TService>
{
TService? Create();
}
public interface IProvider<TParameter, TService>
{
TService? Get(TParameter value);
}
public interface IProvider<TService>
{
TService? Get();
}