defval / di

🛠 A full-featured dependency injection container for go programming language.
MIT License
232 stars 13 forks source link

Handle embed unnamed dependency #29

Closed defval closed 3 years ago

defval commented 3 years ago

Test case (container_test:840):

t.Run("constructor with injectable embed pointer", func(t *testing.T) {
    c, err := di.New()
    require.NoError(t, err)
    type InjectableType struct {
        di.Inject
        *http.ServeMux
    }
    mux := &http.ServeMux{}
    require.NoError(t, c.Provide(func() *http.ServeMux { return mux }))
    require.NoError(t, c.Provide(func() *InjectableType { return &InjectableType{} }))
    var result *InjectableType
    require.NoError(t, c.Resolve(&result))
    require.NotNil(t, result.ServeMux)
    require.Equal(t, fmt.Sprintf("%p", mux), fmt.Sprintf("%p", result.ServeMux))
})
defval commented 3 years ago

Added in v1.7.0