Skip to content

support passing receiver method as provider #4

@zzzz465

Description

@zzzz465

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

When a Wire provider function is a trivial method delegate — its only purpose is to call a method on one of its parameters and return the result — it adds boilerplate without any value.

func DatabaseProvider(opts *APIServerDatabaseOptions) (*gorm.DB, error) {
  return opts.ToDB()
}

var Set = wire.NewSet(
  DatabaseProvider, // wrapper just to call opts.ToDB()
   // ...
)

Describe the solution you'd like

support below pattern for simpler provider function passing

var Set = wire.NewSet(
  (*APIServerDatabaseOptions).ToDB, // directly use the method
  // ...
)

Describe alternatives you've considered

I think this is the simplest way to solve this problem.

Additional context

I used goforj/wire v1.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions