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