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

mvc controllers and methods: provide mvc.Application automatically

Former-commit-id: 991d8e72c3c231813a455dd0680cd8a83b82abb1
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-05-06 08:00:56 +03:00
parent d19672115b
commit 8c470e46a2
3 changed files with 60 additions and 3 deletions

View File

@@ -506,7 +506,7 @@ type testControllerNotCreateNewDueManuallySettingAllFields struct {
}
func (c *testControllerNotCreateNewDueManuallySettingAllFields) AfterActivation(a AfterActivation) {
if n := len(a.DependenciesReadOnly()) - len(hero.BuiltinDependencies); n != 1 {
if n := len(a.DependenciesReadOnly()) - len(hero.BuiltinDependencies) - 1; /* Application */ n != 1 {
c.T.Fatalf(`expecting 1 dependency;
- the 'T' and the 'TitlePointer' are manually binded (nonzero fields on initilization)
- controller has no more than these two fields, it's a singleton
@@ -624,3 +624,24 @@ func TestControllersInsideControllerDeep(t *testing.T) {
e := httptest.New(t, app)
e.GET("/something").Expect().Status(httptest.StatusOK).Body().Equal("foo bar")
}
type testApplicationDependency struct {
App *Application
}
func (c *testApplicationDependency) Get() string {
return c.App.Name
}
func TestApplicationDependency(t *testing.T) {
app := iris.New()
m := New(app).SetName("app1")
m.Handle(new(testApplicationDependency))
m2 := m.Clone(app.Party("/other")).SetName("app2")
m2.Handle(new(testApplicationDependency))
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("app1")
e.GET("/other").Expect().Status(httptest.StatusOK).Body().Equal("app2")
}