Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Add a convenience function to auto inject all public fields from struct #286

@h7kanna

Description

@h7kanna

Is your feature request related to a problem? Please describe.

wire.FieldsOf is a useful function to inject Fields from a struct. But it needs all the fields to be explicitly listed.
If the Struct only has public fields and all of them have to be injected, there should be an easy way to state it.

For example. I have an application that loads config from YAML to Config struct. Its purpose is only a holder of the configuration (loaded from the environment). Initialization looks like below

type Config struct {
	App        *app.Config
	Auth       *auth.Config
	Router         *router.Config        
	Logger         *logger.Config
	HTTPServer     *httpserver.Config
}

var New = wire.NewSet(
	LoadConfigFromEnv,
	wire.FieldsOf(
		new(*Config),
		"App",
		"Auth",
		"Logger",
		"HTTPServer",
		"Router",
	),
)

Describe the solution you'd like

Create a public API function wire.AllFieldsOf. So that declaration becomes.

var New = wire.NewSet(
	LoadConfigFromEnv,
	wire.AllFieldsOf(new(*Config)),
)

Describe alternatives you've considered

The alternative is of course to list the fields as it is done currently

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions