Skip to content

Ability to use fx.As and fx.ResultTags for the same Provider #1214

Description

@Dan6erbond

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

When annotating a provider function with fx.As() and fx.ResultTags() at the same time, Fx fails with an error:

2024-06-12T08:18:56.009Z        ERROR   fxevent/zap.go:59       start failed    {"error": "missing dependencies for function \"gitea.example.com/myproject/http/httpfx\".ConfigureServer (/workspaces/myproject/http/httpfx/module.go:20): missing type: http.Handler", "errorVerbose": "missing dependencies for function \"gitea.example.com/myproject/http/httpfx\".ConfigureServer\n\t/workspaces/carbase-backend/http/httpfx/module.go:20:\nmissing type:\n\t- http.Handler (did you mean to Provide it?)"}

Describe the solution you'd like
A clear and concise description of what you want to happen.

It would be great if I could do this:

var Module = fx.Module("chi",
	fx.Provide(
		fx.Annotate(
			NewRouter,
			fx.As(new(http.Handler)),
			fx.As(new(chi.Router)),
			fx.ResultTags(`name:"router"`),
		),
	),
)

Allowing parts of my application to expect the router while my core bootstrapping logic isn't coupled to Chi in any way and just accepts a router.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

At the moment I just ensure only one http.Handler is available in the DI.

Is this a breaking change?
We do not accept breaking changes to the existing API. Please consider if your proposed solution is backwards compatible. If not, we can help you make it backwards compatible, but this must be considered when we consider new features.

I don't think so.

Additional context
Add any other context or screenshots about the feature request here.

The code above should give a good overview of what I'm trying to achieve, as I want to decouple my HTTP server from whichever router I end up using and just attach the http.Handler to it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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