Provide:
ctx = dpi.ProvideWithContext(ctx,
// eg inject B to A, ServiceB *ServiceB `inject:"true,lazy"`
services.NewServiceA(ctx),
// eg inject A to B, ServiceA *ServiceA `inject:"true,lazy"`
services.NewServiceB(ctx),
)
Consume
type ServiceA struct {
DB *database.DBConn `inject:"true"`
ServiceB *ServiceB `inject:"true,lazy"`
}
func NewServiceA(ctx context.Context) *ServiceA {
s := &ServiceA{}
if _, err := dpi.InjectFromContext(ctx, s); err != nil {
panic(err)
}
return s
}