Nacelle

Go service framework
/

How to inject dependencies into composite fields

This guide describes a feature of the github.com/go-nacelle/service package. See related documentation.


Injection also works on structs containing composite fields. The following example successfully assigns the registered value to the field Child.Base.Service.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
type Base struct {
	Service *SomeExample `service:"example"`
}

type Child struct {
	*Base
}

child := &Child{}
if err := container.Inject(child); err != nil {
	// handle error
}