uber-go / dig

A reflection based dependency injection toolkit for Go.
https://go.uber.org/dig
MIT License
3.85k stars 206 forks source link

Add CanInvoke for easy validation #182

Open robfig opened 6 years ago

robfig commented 6 years ago

I would like to be able to write a unit test that validates that the set of dig providers is correct to invoke a particular function. Since some providers are RPC clients and DB clients which are required by other injected types, it's impossible to do this without making it an integration test, which feels unnecessarily brittle.

How do you feel about providing a method that just checks the needed items are provided to Invoke something, returning the error that would have been returned otherwise?

akshayjshah commented 6 years ago

Hi! I'm so sorry for the long delay here - I didn't realize that I wasn't subscribed to this repo. (And thanks for writing Revel!)

I'm definitely open to this. If you don't have the bandwidth to open a PR, I'll keep it in our backlog.

If you haven't, take a look at fx (github.com/uber-go/fx) too - it's the service framework that we built around this package.