diff options
author | Alexander Kiryukhin <i@neonxp.dev> | 2022-07-17 02:52:20 +0300 |
---|---|---|
committer | Alexander Kiryukhin <i@neonxp.dev> | 2022-07-17 02:52:20 +0300 |
commit | d3ad517530f0b03e66fe575afe90ec1429ec567d (patch) | |
tree | 70c617b73b08c0e48fddd643b111350102f7c5ad | |
parent | 9d2403804cbe620f000792e22a4573e46d631fac (diff) |
fix readme
-rw-r--r-- | README.md | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -38,19 +38,19 @@ func Register[T any](id string, constructor func() (*T, error)) ### Example ```go - di.Register("serviceA", func() (*ServiceA, error) { // <- Register service A - return &ServiceA{}, nil - }) - di.Register("serviceB", func() (*ServiceB, error) { // <- Register service B, that depends from service A - serviceA, err := di.Get[ServiceA]() // <- Get dependency from container by type - if err != nil { - return nil, err - } - - return &ServiceB{ - ServiceA: serviceA[0], - }, nil - }) +di.Register("serviceA", func() (*ServiceA, error) { // <- Register service A + return &ServiceA{}, nil +}) +di.Register("serviceB", func() (*ServiceB, error) { // <- Register service B, that depends from service A + serviceA, err := di.Get[ServiceA]() // <- Get dependency from container by type + if err != nil { + return nil, err + } + + return &ServiceB{ + ServiceA: serviceA[0], + }, nil +}) // Do work ... service, err := di.GetById[ServiceB]("serviceB") // <- Get instantinated service B |