mardi 7 mai 2019

Best Practice for Managing Large Application Configuration

Say I am building a large service MyService, which contains a variety of SubServices that may perform operations in a multithreaded context. Designed in C++ like so:

class MyService : public MyServiceInterface{
public:
    // Some public methods.
private:
    // Some private methods.

    // Some sub services. Assume that these are dependency injected.
    std::shared_ptr<SubServiceA> a;
    std::shared_ptr<SubServiceB> b;
    std::shared_ptr<SubServiceC> c;

MyService is configurable through a user-defined file which we parse into a data structure MyServiceConfig. This configuration is not read-only, the application may edit it during the course of operation. Assume that we have all of the concurrency primitives in place to manage any accesses.

My question is this- if all of my SubServices require not-necessarily exclusive parts of this configuration, is it good practice to pass a std::shared_ptr<MyServiceConfig> to any SubService? It seems strange to me to expose the entire configuration to every system, if it is not required. There are several solutions to this (passing individual pieces if the subset of required configuration is small, maintaining internal structures in MyServiceConfig that perform logical division for known SubServices), but I'm failing to see clearly what would be best. Is there an established best-practice pattern for configuring large-scale services and their sub-services?

Aucun commentaire:

Enregistrer un commentaire