Closed sabbadino closed 7 months ago
I suspect the class is sealed for performance reasons. There is nothing stopping you from doing something like this:
var settings = new Dictionary<string, FusionCacheEntryOptions>();
string[] names = ["Foo"];
foreach (var name in names)
{
var section = builder.Configuration.GetSection(name);
var options = new FusionCacheEntryOptions();
section.Bind(options);
settings.Add(name, options);
}
builder.Services.AddSingleton(settings);
Or you could just wrap the type instead of inheriting from it.
public class NamedFusionCacheEntryOptions
{
public string Name { get; set; }
public FusionCacheEntryOptions CacheEntryOptions { get; set; }
}
Oh yes, composition over inheritance.. it was actually quite a naive question :)
Hi all, sorry for the delay. Thanks @pbolduc for the hint! @sabbadino did it work?
Problem
Suppose I have an application with many different FusionCacheEntryOptions requirement for different type of items to be cached. I need to store each of such different setting in IConfiguration
it would be nice to reuse the FusionCacheEntryOptions but it is sealed
Solution
If FusionCacheEntryOptions was not sealed i could do something like this
and then I coudl do something like this when i need such settings
Alternatives
Is there another declarative, IConfiguration based solution I ma not aware to manage a large set of FusionCacheEntryOptions values ?