karlkfi / inject

Dependency injection library for Go (golang)
Apache License 2.0
80 stars 7 forks source link

Add support for variadic arguments on provider constructor #7

Closed mumia closed 7 years ago

mumia commented 7 years ago

Example:

dependencies.graph.Define(
        &dependencies.RouteRegistry,
        inject.NewProvider(
            routes.NewRouteRegistry,
            &dependencies.AuthenticationRoutes,
            &dependencies.AccountRoutes,
            &dependencies.BankRoutes,
            &dependencies.BaseRoutes,
        ),
    )

Where routes.NewRouteRegistry is:

func NewRouteRegistry(routes ...Route) RouteRegistry
karlkfi commented 7 years ago

Sorry for the long silence. I know I don't have CI or unit tests for every feature, but can you add a test that covers this feature and show that it and the other tests still pass?

mumia commented 7 years ago

@karlkfi We are already using this in a production environment. :) I will write some tests so you can merge it. Thanks for the reply.

mumia commented 7 years ago

The tests are passing: $ go test -v ./... ? github.com/mumia/inject [no test files] === RUN TestExtractByType --- PASS: TestExtractByType (0.00s) === RUN TestExtractByTypeNoMatch --- PASS: TestExtractByTypeNoMatch (0.00s) === RUN TestExtractByTypeMultiMatch --- PASS: TestExtractByTypeMultiMatch (0.00s) === RUN TestExtractAssignable --- PASS: TestExtractAssignable (0.00s) === RUN TestExtractAssignableNoMatch --- PASS: TestExtractAssignableNoMatch (0.00s) === RUN TestExtractAssignableMultiMatch --- PASS: TestExtractAssignableMultiMatch (0.00s) === RUN TestFindByType --- PASS: TestFindByType (0.00s) === RUN TestFindAssignable --- PASS: TestFindAssignable (0.00s) === RUN TestGraphSupportsInterfaces --- PASS: TestGraphSupportsInterfaces (0.00s) === RUN TestGraphSupportsStructPointers --- PASS: TestGraphSupportsStructPointers (0.00s) === RUN TestGraphSupportsProviderConstructorArgs --- PASS: TestGraphSupportsProviderConstructorArgs (0.00s) === RUN TestGraphSupportsAutoProvider --- PASS: TestGraphSupportsAutoProvider (0.00s) === RUN TestGraphSupportsDownCasting --- PASS: TestGraphSupportsDownCasting (0.00s) === RUN TestGraphSupportsPartialResolution --- PASS: TestGraphSupportsPartialResolution (0.00s) === RUN TestGraphLifecycle --- PASS: TestGraphLifecycle (0.00s) === RUN TestVariadicNone --- PASS: TestVariadicNone (0.00s) === RUN TestVariadicOne --- PASS: TestVariadicOne (0.00s) === RUN TestVariadicAll --- PASS: TestVariadicAll (0.00s) PASS ok github.com/mumia/inject/test 0.009s ? github.com/mumia/inject/test/variadic [no test files]

:)

karlkfi commented 7 years ago

Tests are failing because one of your imports is importing your fork, not the real path

karlkfi commented 7 years ago

Thanks!

hori-ryota commented 7 years ago

This change has broken for slice arguments.

        if inType.Kind() == reflect.Slice {
            inType = inType.Elem()
        }

If arg type is []uint , inType will be uint and fail AssignableTo and ConvertibleTo .

Issue created #8