Added support for per site options and OpenID Connect
This commit is contained in:
35
Oqtane.Server/Infrastructure/Options/SiteOptionsManager.cs
Normal file
35
Oqtane.Server/Infrastructure/Options/SiteOptionsManager.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class SiteOptionsManager<TOptions> : IOptions<TOptions>, IOptionsSnapshot<TOptions> where TOptions : class, new()
|
||||
{
|
||||
private readonly IOptionsFactory<TOptions> _factory;
|
||||
private readonly IOptionsMonitorCache<TOptions> _cache; // private cache
|
||||
|
||||
public SiteOptionsManager(IOptionsFactory<TOptions> factory, IOptionsMonitorCache<TOptions> cache)
|
||||
{
|
||||
_factory = factory;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public TOptions Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get(Options.DefaultName);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual TOptions Get(string name)
|
||||
{
|
||||
name = name ?? Options.DefaultName;
|
||||
return _cache.GetOrAdd(name, () => _factory.Create(name));
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user