generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwithgrouped.go
44 lines (38 loc) · 1.13 KB
/
withgrouped.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
42
43
44
package imbue
// Group is a constraint for a type that identifies a group of dependencies.
//
// Groups are used to group multiple dependencies of different types that are
// related in some way.
//
// Groups are defined by declaring a named type that uses imbue.Group as its
// underlying type.
type Group interface {
group()
}
// FromGroup declares a dependency on a type within a specific group.
//
// It is used as a parameter type within user-defined functions passed to
// WithX(), DecorateX(), and InvokeX() to request of type T that is within the
// group G.
type FromGroup[G Group, T any] struct {
value T
}
// Group returns the name given to the group.
func (v FromGroup[G, T]) Group() string {
return typeOf[G]().Name()
}
// Value returns the dependency value.
func (v FromGroup[G, T]) Value() T {
return v.value
}
// inGroup wraps a value of type T to present it as a FromGroup[G, T].
func inGroup[G Group, T any](v T) FromGroup[G, T] {
return FromGroup[G, T]{
value: v,
}
}
// WithGroupedOption is an option that changes the behavior of a call to
// WithXGrouped().
type WithGroupedOption interface {
applyWithGroupedOption()
}