Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow injectors to have their provider map modified after being built #10

Open
TehPers opened this issue Mar 31, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@TehPers
Copy link
Owner

TehPers commented Mar 31, 2021

Suppose a config is reloaded during execution of a program. This would allow services to be reconfigured based on the changes in that config. Currently, it's somewhat possible using factories:

struct FooFactory {
    injector: Injector,
    config: Svc<Mutex<Config>>
}

impl FooFactory {
    pub fn new(injector: Injector, config: Svc<Mutex<Config>>) -> Self {
        FooFactory {
            injector,
            config,
        }
    }

    pub fn get(&self) -> InjectResult<Svc<dyn Foo>> {
        match self.config.lock().unwrap().foo_impl {
            FooImpl::Bar => self.injector.get::<Svc<Bar>>().map(|bar| bar as Svc<dyn Foo>),
            // ...
        }
    }
}

This is a lot of work to reconfigure just a single service based on a config reloaded at runtime. It might be better to instead expose some functions to mutate the provider map in existing Injectors.

@TehPers TehPers added the enhancement New feature or request label May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant