From a3b5797e546fd51e374de403add4c409fba6ba56 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 11 Jun 2021 11:11:36 +0300 Subject: [PATCH] add a shortcut for ConfigureContainer().Use as UseFunc on Party --- core/router/api_builder.go | 11 ++++++++++- core/router/party.go | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/router/api_builder.go b/core/router/api_builder.go index ea95ff42..892c9117 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -421,11 +421,20 @@ func (api *APIBuilder) RegisterDependency(dependencies ...interface{}) { // See the `ConfigureContainer` for more features regrading // the dependency injection, mvc and function handlers. // -// This method is just a shortcut for the `ConfigureContainer().Handle` one. +// This method is just a shortcut of the `ConfigureContainer().Handle`. func (api *APIBuilder) HandleFunc(method, relativePath string, handlersFn ...interface{}) *Route { return api.ConfigureContainer().Handle(method, relativePath, handlersFn...) } +// UseFunc registers a function which can accept one or more +// dependencies (see RegisterDependency) and returns an iris.Handler +// or a result of and/or an error. +// +// This method is just a shortcut of the `ConfigureContainer().Use`. +func (api *APIBuilder) UseFunc(handlersFn ...interface{}) { + api.ConfigureContainer().Use(handlersFn...) +} + // GetRelPath returns the current party's relative path. // i.e: // if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users". diff --git a/core/router/party.go b/core/router/party.go index f4c487f5..0776010e 100644 --- a/core/router/party.go +++ b/core/router/party.go @@ -100,6 +100,12 @@ type Party interface { // // This method is just a shortcut for the `ConfigureContainer().Handle` one. HandleFunc(method, relativePath string, handlersFn ...interface{}) *Route + // UseFunc registers a function which can accept one or more + // dependencies (see RegisterDependency) and returns an iris.Handler + // or a result of and/or an error. + // + // This method is just a shortcut of the `ConfigureContainer().Use`. + UseFunc(handlersFn ...interface{}) // GetRelPath returns the current party's relative path. // i.e: