allow new items to be added to sub menus at runtime, from a config file
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user