Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Add support for a lazy ConfigurationProvider #584

Closed

Description

@HaoK

Today our base provider only handles eagerly loading all key/values in load, we should have some way to delay loading the values until needed

Activity

  1. changed the title [-]Add support for a lazy ConfigurationProvder[/-] [+]Add support for a lazy ConfigurationProvider[/+] on Jan 13, 2017
  2. added this to the 2.0.0 milestone on Jan 13, 2017
  3. passuied commented on Feb 24, 2017

    @passuied

    @HaoK
    We have just implemented our custom provider using lazy loading by adding logic to the TryGet().

    Our source/provider plugs to DI and resolves our current request context to figure out which client this setting is for.
    It will then load all client-specific settings if missing and store them in sub sections of Data dictionary (e.g. clientA:MyOptions:Value, vs :MyOptions:Value).
    The biggest roadblock now is to reload only a given client setting and not the entire source...
    Was wondering if there might be a way to create a multi-tenant source that adds inner sources dynamically (or in the worst case scenario add them all automtically at startup). Then we might be able to only invalidate one of the inner sources.

    Just a thought at this point. Might not be possible or not a very elegant solution...

  4. HaoK commented on Feb 24, 2017

    @HaoK
    MemberAuthor

    Are you able to have a provider per tenant? That would align with how reload works

  5. self-assigned this
    on Feb 24, 2017
  6. HaoK commented on Feb 24, 2017

    @HaoK
    MemberAuthor

    Some initial thoughts for how this might look, will try switching a few providers over to this to see how it feels.

       public class LazyConfigurationProvider : IConfigurationProvider {
          private ConfigurationReloadToken _reloadToken = new ConfigurationReloadToken();
          private IEnumerable<string> _allKeys;
    
          protected IDictionary<string, string> Data { get; set; }
    
          public abstract IEnumerable<string> LoadAllKeys();
          public abstract LoadValue(string key);
       
          // Interface methods
    
          IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys, string parentPath) {
             // Reuse same code as ConfigurationProvider with _allKeys;
          }
    
          bool TryGet(string key, out string value) {
              // If we don't have data already, call LoadValue and store in Data
          }
          void Set(string key, string value) => Data[key] = value;
          IChangeToken GetReloadToken() => _reloadToken;
          void Load() {
               _allKeys = LoadAllKeys();
               // We could setup the dictionary with a bunch of Lazy<string> calls to LoadValue to simplify TryGet
          }
       }
  7. passuied commented on Feb 24, 2017

    @passuied

    @HaoK

    Are you able to have a provider per tenant? That would align with how reload works

    The problem is I would prefer to avoid initializing all client sources/providers at startup.
    First it may have a performance impact to set up a config with 1000+ sources that may/may not place any request.
    But also how would I handle cases where a client is being provisioned without having to restart the service.

    I would rather have the ability to dynamically add the source at runtime the first time a client request comes in.

    This is how I'm handling it right now but within a single source. I pull the client settings upon request if not there already.

    However when I need to invalidate a single client this model doesn't work.

    Thoughts?

  8. HaoK commented on Feb 24, 2017

    @HaoK
    MemberAuthor

    I'll have to think about this a bit more, we'll discuss this in the next triage as we are seeing a lot of requests about multi-tenancy scenarios. @glennc

  9. HaoK commented on Mar 27, 2017

    @HaoK
    MemberAuthor

    We've decided not to purse changes in this direction after discussing our plans for 2.0. This is a fairly advanced scenario that individual providers can attempt if so desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions