Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

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

@TehPers

Description

@TehPers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions