1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 12:57:05 +00:00

.DI() to ConfigureContainer(...builders)

Former-commit-id: 169671a8b5b706dc8f136e68c1a060f27a2c421b
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-17 15:56:36 +03:00
parent eafa63da50
commit 1bb76853a9
12 changed files with 108 additions and 65 deletions

View File

@@ -113,7 +113,7 @@ func (repo *repository) register(route *Route, rule RouteRegisterRule) (*Route,
// and child routers.
type APIBuilder struct {
// the per-party APIBuilder with DI.
apiBuilderDI *APIBuilderDI
apiBuilderDI *APIContainer
// the api builder global macros registry
macros *macro.Macros
@@ -171,7 +171,7 @@ func NewAPIBuilder() *APIBuilder {
routes: new(repository),
}
api.apiBuilderDI = &APIBuilderDI{
api.apiBuilderDI = &APIContainer{
Self: api,
Container: hero.New(),
}
@@ -179,8 +179,22 @@ func NewAPIBuilder() *APIBuilder {
return api
}
// DI returns the APIBuilder featured with Dependency Injection.
func (api *APIBuilder) DI() *APIBuilderDI {
// ConfigureContainer accepts one or more functions that can be used
// to configure dependency injection features of this Party
// such as register dependency and register handlers that will automatically inject any valid dependency.
// However, if the "builder" parameter is nil or not provided then it just returns the *APIContainer,
// which automatically initialized on Party allocation.
//
// It returns the same `APIBuilder` featured with Dependency Injection.
func (api *APIBuilder) ConfigureContainer(builder ...func(*APIContainer)) *APIContainer {
for _, b := range builder {
if b == nil {
continue
}
b(api.apiBuilderDI)
}
return api.apiBuilderDI
}
@@ -529,7 +543,7 @@ func (api *APIBuilder) Party(relativePath string, handlers ...context.Handler) P
// based on the fullpath.
childContainer := api.apiBuilderDI.Container.Clone()
childAPI.apiBuilderDI = &APIBuilderDI{
childAPI.apiBuilderDI = &APIContainer{
Self: childAPI,
Container: childContainer,
}