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

dig: README examples not idiomatic #285

Closed
glibsm opened this issue Feb 17, 2017 · 3 comments
Closed

dig: README examples not idiomatic #285

glibsm opened this issue Feb 17, 2017 · 3 comments

Comments

@glibsm
Copy link
Collaborator

glibsm commented Feb 17, 2017

Need to take a pass. Includes things like:

err := dig.Resolve(&o) // notice the pointer to a pointer as param type
if err == nil {
    // o is ready to use
}
err = g.Resolve(&f1)
require.NoError(t, err)
@glibsm glibsm mentioned this issue Feb 17, 2017
2 tasks
@dmcaulay
Copy link
Contributor

I'd like to see some guidelines for usage in the docs. I started to integrate dig into one of my projects and found myself trying to solve the wrong problems with dig. Here are a couple rules I've started to form:

  • Dependency injection should only be used to resolve dependencies at service startup.
  • Application code should receive dependencies in their constructors and not use dig.Resolve directly.
  • Tests should create dependencies manually and pass them into service constructors.

I'd also like to see recommendations on where dig.Register code should live.

Dependency injection is very cool, but without better guidelines it might start leading to magical and messy code that's difficult to manage.

Feel free to strongly disagree with any of this 😃.

@anuptalwalkar
Copy link
Contributor

anuptalwalkar commented Feb 21, 2017

Application code should receive dependencies in their constructors and not use dig.Resolve directly.
Good start. This gets tricky when you have a list of dependency to be consumed. May be worthwhile to investigate intelligent way to perform dig.Resolve().

@glibsm
Copy link
Collaborator Author

glibsm commented Mar 23, 2017

moved to uber-go/dig#1

@glibsm glibsm closed this as completed Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants