Skip to content

Commit 20d9513

Browse files
author
yoyofx
committed
Examples
1 parent 4c3dfd1 commit 20d9513

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
# DI
22
Dependency injection for Go programming language.
33

4-
Dependency injection is one form of the broader technique of inversion of control. It is used to increase modularity of the program and make it extensible.
4+
Dependency injection is one form of the broader technique of inversion of control. It is used to increase modularity of the program and make it extensible.
5+
6+
## Examples
7+
```go
8+
type A struct {
9+
Name string
10+
}
11+
12+
func NewA() *A {
13+
r := rand.New(rand.NewSource(time.Now().UnixNano()))
14+
name := "A-" + strconv.Itoa(r.Int())
15+
return &A{Name: ls}
16+
}
17+
18+
services := NewServiceCollection()
19+
services.AddSingleton(NewA)
20+
serviceProvider := services.Build()
21+
22+
var env *A
23+
_ = serviceProvider.GetService(&env) // used
24+
```

0 commit comments

Comments
 (0)