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

Add support for a lazy ConfigurationProvider #584

Closed
HaoK opened this issue Jan 13, 2017 · 6 comments
Closed

Add support for a lazy ConfigurationProvider #584

HaoK opened this issue Jan 13, 2017 · 6 comments
Assignees

Comments

@HaoK
Copy link
Member

HaoK commented Jan 13, 2017

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

@HaoK HaoK changed the title Add support for a lazy ConfigurationProvder Add support for a lazy ConfigurationProvider Jan 13, 2017
@HaoK HaoK added this to the 2.0.0 milestone Jan 13, 2017
@passuied
Copy link

passuied commented Feb 24, 2017

@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...

@HaoK
Copy link
Member Author

HaoK commented Feb 24, 2017

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

@HaoK HaoK self-assigned this Feb 24, 2017
@HaoK
Copy link
Member Author

HaoK commented Feb 24, 2017

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
      }
   }

@passuied
Copy link

@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?

@HaoK
Copy link
Member Author

HaoK commented Feb 24, 2017

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

@HaoK
Copy link
Member Author

HaoK commented Mar 27, 2017

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.

@HaoK HaoK closed this as completed Mar 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants