-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority.go
35 lines (29 loc) · 1012 Bytes
/
priority.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
package examples
import (
"github.com/dbsystel/golang-runtime-di/pkg/di"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// PriorityDependency is the interface for a dependency to be injected
type PriorityDependency interface {
Woop()
}
// PriorityComponent is the component to be injected
type PriorityComponent struct{ Name string }
func (c *PriorityComponent) Woop() {}
// PriorityConsumer is the consumer for SimpleDependency
type PriorityConsumer struct {
// Dependency will be injected by priority
Dependency PriorityDependency `inject:""`
}
var _ = Describe("Priority example", func() {
It("should wire components after priority", func() {
scope := &di.Scope{}
scope.MustRegister(&PriorityComponent{"soccer"})
// lower value = higher priority
scope.MustRegister(&PriorityComponent{"squash"}).WithPriority(-1)
instance := &PriorityConsumer{}
scope.MustWire(instance)
Expect(instance).To(Equal(&PriorityConsumer{Dependency: &PriorityComponent{Name: "squash"}}))
})
})