aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kiryukhin <i@neonxp.dev>2022-07-17 02:52:20 +0300
committerAlexander Kiryukhin <i@neonxp.dev>2022-07-17 02:52:20 +0300
commitd3ad517530f0b03e66fe575afe90ec1429ec567d (patch)
tree70c617b73b08c0e48fddd643b111350102f7c5ad
parent9d2403804cbe620f000792e22a4573e46d631fac (diff)
fix readme
-rw-r--r--README.md26
1 files changed, 13 insertions, 13 deletions
diff --git a/README.md b/README.md
index 6a04eb8..c20db6e 100644
--- a/README.md
+++ b/README.md
@@ -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