mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
add a warning on mvc if someone didn't read the examples or the godocs and .Register dependencies after .Handle
a developer sent a direct question message from our facebook page: https://www.facebook.com/iris.framework/ Former-commit-id: ebd7b4bc9078d4952799b4498ce4dfb0ed4c8072
This commit is contained in:
19
mvc/mvc.go
19
mvc/mvc.go
@@ -1,10 +1,14 @@
|
||||
package mvc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/router"
|
||||
"github.com/kataras/iris/hero"
|
||||
"github.com/kataras/iris/hero/di"
|
||||
|
||||
"github.com/kataras/golog"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -37,6 +41,7 @@ var (
|
||||
type Application struct {
|
||||
Dependencies di.Values
|
||||
Router router.Party
|
||||
Controllers []*ControllerActivator
|
||||
}
|
||||
|
||||
func newApp(subRouter router.Party, values di.Values) *Application {
|
||||
@@ -105,7 +110,19 @@ func (app *Application) Configure(configurators ...func(*Application)) *Applicat
|
||||
//
|
||||
// Example: `.Register(loggerService{prefix: "dev"}, func(ctx iris.Context) User {...})`.
|
||||
func (app *Application) Register(values ...interface{}) *Application {
|
||||
if len(values) > 0 && app.Dependencies.Len() == 0 && len(app.Controllers) > 0 {
|
||||
allControllerNamesSoFar := make([]string, len(app.Controllers))
|
||||
for i := range app.Controllers {
|
||||
allControllerNamesSoFar[i] = app.Controllers[i].Name()
|
||||
}
|
||||
|
||||
golog.Warnf(`mvc.Application#Register called after mvc.Application#Handle.
|
||||
The controllers[%s] may miss required dependencies.
|
||||
Set the Logger's Level to "debug" to view the active dependencies per controller.`, strings.Join(allControllerNamesSoFar, ","))
|
||||
}
|
||||
|
||||
app.Dependencies.Add(values...)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -173,6 +190,8 @@ func (app *Application) Handle(controller interface{}) *Application {
|
||||
}); okAfter {
|
||||
after.AfterActivation(c)
|
||||
}
|
||||
|
||||
app.Controllers = append(app.Controllers, c)
|
||||
return app
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user