forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.go
41 lines (32 loc) · 1.04 KB
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package container
import (
"reflect"
)
// Scope is a special type used to define a provider scope.
//
// Special scoped constructors can be used with Provide by declaring a
// constructor with an input parameter of type Scope. These constructors
// should construct an unique value for each dependency based on scope and will
// be called at most once per scope.
//
// Constructors passed to ProvideWithScope can also declare an input parameter
// of type Scope to retrieve their scope but these constructors will be called at most once.
type Scope interface {
isScope()
// Name returns the name of the scope which is unique within a container.
Name() string
}
// NewScope creates a new scope with the provided name. Only one scope with a
// given name can be created per container.
func newScope(name string) Scope {
return &scope{name: name}
}
type scope struct {
name string
}
func (s *scope) Name() string {
return s.name
}
func (s *scope) isScope() {}
var scopeType = reflect.TypeOf((*Scope)(nil)).Elem()
var stringType = reflect.TypeOf("")