Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed Jul 12, 2021
1 parent 4c3dfd1 commit 20d9513
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# DI
Dependency injection for Go programming language.

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.
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.

## Examples
```go
type A struct {
Name string
}

func NewA() *A {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
name := "A-" + strconv.Itoa(r.Int())
return &A{Name: ls}
}

services := NewServiceCollection()
services.AddSingleton(NewA)
serviceProvider := services.Build()

var env *A
_ = serviceProvider.GetService(&env) // used
```

0 comments on commit 20d9513

Please sign in to comment.