-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
111 lines (84 loc) · 2.23 KB
/
options.go
File metadata and controls
111 lines (84 loc) · 2.23 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2024 OrigAdmin. All rights reserved.
*/
package kore
// Common Types for DI management
type (
Category string
Scope string
Priority int
)
const (
// GlobalScope is the default system fallback scope.
GlobalScope Scope = "_global"
// DefaultName is the system key for the active/default instance.
DefaultName = "_default"
)
// --- Registration Options (Providers) ---
type RegistrationOptions struct {
Resolver Resolver
Scopes []Scope
Priority Priority
Tag string
}
type RegisterOption func(*RegistrationOptions)
func WithScope(s Scope) RegisterOption {
return func(o *RegistrationOptions) { o.Scopes = append(o.Scopes, s) }
}
func WithPriority(p Priority) RegisterOption {
return func(o *RegistrationOptions) { o.Priority = p }
}
func WithTag(tag string) RegisterOption {
return func(o *RegistrationOptions) { o.Tag = tag }
}
func WithResolver(res Resolver) RegisterOption {
return func(o *RegistrationOptions) { o.Resolver = res }
}
// --- Perspective Options (In/Query) ---
type InOptions struct {
Scope Scope
Tags []string
}
type InOption func(*InOptions)
func WithInScope(s Scope) InOption {
return func(o *InOptions) { o.Scope = s }
}
func WithInTags(tags ...string) InOption {
return func(o *InOptions) { o.Tags = append(o.Tags, tags...) }
}
// --- Loading Options ---
type LoadOptions struct {
Category Category
Scope Scope
Name string
Resolver Resolver
Tags []string
}
type LoadOption func(*LoadOptions)
func ForCategory(cat Category) LoadOption {
return func(o *LoadOptions) { o.Category = cat }
}
func ForName(name string) LoadOption {
return func(o *LoadOptions) { o.Name = name }
}
func ForScope(s Scope) LoadOption {
return func(o *LoadOptions) { o.Scope = s }
}
func WithLoadResolver(res Resolver) LoadOption {
return func(o *LoadOptions) { o.Resolver = res }
}
// --- Container Options ---
type RegistryOptions struct {
CategoryResolvers map[Category]Resolver
}
type RegistryOption func(*RegistryOptions)
func WithCategoryResolvers(res map[Category]Resolver) RegistryOption {
return func(o *RegistryOptions) {
if o.CategoryResolvers == nil {
o.CategoryResolvers = make(map[Category]Resolver)
}
for k, v := range res {
o.CategoryResolvers[k] = v
}
}
}