mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
fix all _examples to the newest mvc, add comments to those examples and add a package-level .Configure in order to make it easier for new users. Add a deprecated panic if app.Controller is used with a small tutorial and future resource link so they can re-write their mvc app's definitions
Former-commit-id: bf07696041be9e3d178ce3c42ccec2df4bfdb2af
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type State uint8
|
||||
type Scope uint8
|
||||
|
||||
const (
|
||||
Stateless State = iota
|
||||
Stateless Scope = iota
|
||||
Singleton
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ type (
|
||||
// see `setState`.
|
||||
HasFields bool
|
||||
CanInject bool // if any bindable fields when the state is NOT singleton.
|
||||
State State
|
||||
Scope Scope
|
||||
}
|
||||
)
|
||||
|
||||
@@ -121,13 +121,13 @@ func (s *StructInjector) setState() {
|
||||
// if the number of static values binded is equal to the
|
||||
// total struct's fields(including unexported fields this time) then set as singleton.
|
||||
if staticBindingsFieldsLength == allStructFieldsLength {
|
||||
s.State = Singleton
|
||||
s.Scope = Singleton
|
||||
// the default is `Stateless`, which means that a new instance should be created
|
||||
// on each inject action by the caller.
|
||||
return
|
||||
}
|
||||
|
||||
s.CanInject = s.State == Stateless && s.HasFields
|
||||
s.CanInject = s.Scope == Stateless && s.HasFields
|
||||
}
|
||||
|
||||
// fill the static bindings values once.
|
||||
@@ -177,15 +177,15 @@ func (s *StructInjector) InjectElem(destElem reflect.Value, ctx ...reflect.Value
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StructInjector) New() reflect.Value {
|
||||
if s.State == Singleton {
|
||||
func (s *StructInjector) Acquire() reflect.Value {
|
||||
if s.Scope == Singleton {
|
||||
return s.initRef
|
||||
}
|
||||
return reflect.New(s.elemType)
|
||||
}
|
||||
|
||||
func (s *StructInjector) NewAsSlice() []reflect.Value {
|
||||
if s.State == Singleton {
|
||||
func (s *StructInjector) AcquireSlice() []reflect.Value {
|
||||
if s.Scope == Singleton {
|
||||
return s.initRefAsSlice
|
||||
}
|
||||
return []reflect.Value{reflect.New(s.elemType)}
|
||||
|
||||
Reference in New Issue
Block a user