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

Better dependency injection syntax #125

Open
tarcieri opened this issue Aug 6, 2019 · 1 comment
Open

Better dependency injection syntax #125

tarcieri opened this issue Aug 6, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@tarcieri
Copy link
Collaborator

tarcieri commented Aug 6, 2019

The current dependency injection syntax is pretty gnarly and looks like this:

#[derive(Component, Debug)]
#[component(inject = "init_foo(depname::Foo)")]
#[component(inject = "init_bar(depname::Bar)")]
pub struct MyComponent {
    pub fn init_foo(&mut self, foo: &mut depname::Foo) -> Result<(), FrameworkError> {
        [...[
    }

    pub fn init_bar(&mut self, bar: &mut depname::Bar) -> Result<(), FrameworkError> {
        [...]
    }
}

It'd be nice to be able to use an attribute macro on the "injector" functions instead. Something like this:

#[derive(Component, Debug)]
#[inject(init_foo, init_bar)]
pub struct MyComponent {
    #[inject]
    pub fn init_foo(&mut self, foo: &mut depname::Foo) -> Result<(), FrameworkError> {
        [...[
    }

    #[inject]
    pub fn init_bar(&mut self, bar: &mut depname::Bar) -> Result<(), FrameworkError> {
        [...]
    }
}

It'd be nice if the #[inject] annotations on individual functions were all that were required, but AFAICT, the #[inject(init_foo, init_bar)] is still needed to thunk between them.

@tarcieri tarcieri added the enhancement New feature or request label Aug 6, 2019
@toadzky
Copy link

toadzky commented Nov 20, 2021

it would also be nice to have a single method that accepts multiple dependencies: inject = init(crate::Foo, crate::Bar)

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

2 participants