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

feature request: auto injection with struct tags #9

Open
darluc opened this issue Jul 8, 2022 · 3 comments
Open

feature request: auto injection with struct tags #9

darluc opened this issue Jul 8, 2022 · 3 comments
Milestone

Comments

@darluc
Copy link

darluc commented Jul 8, 2022

I used some other framework that could auto inject with struct tags.

Something like this:

type Bar interface {
  DoSomething()
}

type Foo struct {
  Bar `inject:""` // or we can use named value here `inject:"name"`
}

do.Provide(injector,  func() ( Bar, err){...})

f, err := do.Invoke[Foo]() // f.Bar should be injected automatically
f.Bar.DoSomething()
@sillydong
Copy link

This is an interesting feature, but will requires reflect to parse the structure and get its tags.

@kcmvp
Copy link

kcmvp commented Oct 3, 2022

another idea is that might a dsl is a good idea even better than struct tag

1: instead of spreading of all the dependencies around the code base, all the dependencies are defined in a dsl. it's very clear from the point of architecture. ( java ecosystem springboot supports xml configuration)

2: dsl is more expressive

3: building a dsl from scratch is not simple task, we can build it base on https://github.com/hashicorp/hcl

@samber
Copy link
Owner

samber commented Jan 28, 2023

The DSL option is nice when you have existing tooling. This library should be dead simple, with no IDE plugin or CLI.

I will create a small PR with a proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants