uber-go / dig

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

feat: add function runtime to dig.CallbackInfo #412

Closed tchung1118 closed 3 months ago

tchung1118 commented 3 months ago

This change adds runtime of the associated constructor or decorator to dig.CallbackInfo.

For example, users can access the runtime of a particular constructor by:

c := dig.New()
c.Provide(NewFoo, dig.WithProviderCallback(func(ci dig.CallbackInfo) {
    if ci.Error == nil {
        fmt.Printf("constructor %q finished running in %v", ci.Name, ci.Runtime)
    }
}))

This change is a prerequisite for adding https://github.com/uber-go/fx/issues/1213 to report runtime of constructors in Run events.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.35%. Comparing base (897df36) to head (1ed1d62). Report is 1 commits behind head on master.

:exclamation: Current head 1ed1d62 differs from pull request most recent head 26d26ec

Please upload reports for the commit 26d26ec to get more accurate results.

Files Patch % Lines
container.go 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #412 +/- ## ========================================== - Coverage 98.40% 98.35% -0.05% ========================================== Files 22 23 +1 Lines 1507 1524 +17 ========================================== + Hits 1483 1499 +16 - Misses 15 16 +1 Partials 9 9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.