Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed Sep 24, 2019
1 parent a5eb2ee commit e22801a
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
# Container
A IoC Container written in Go
An IoC Container written in Go

## Documentation

### Installation
To install this package run following command in the root of your project

```bash
go get github.com/golobby/ioc
go get github.com/golobby/container
```

### Binding
To bind an abstraction to a concrete for further singletion resolution:
To bind an abstraction to a concrete for further singleton resolutions:

```go
i := ioc.Container{}
i.Singleton(func() Repository {
return &UserRepository{}
container.Singleton(func() Abstraction {
return Implementation
})
```
And to bind an abstraction to a concrete for further transient resolution:

And to bind an abstraction to a concrete for further transient resolutions:

```go
container.Transient(func() Abstraction {
return Implementation
})
```

For example:

```go
i := ioc.Container{}
i.Transient(func() Repository {
return &UserRepository{}
import "github.com/golobby/container"

container.Singleton(func() Mailer {
return &Gmail{}
})
```

### Resolving

To make (resolve) an abstraction:
To make (resolve) a concrete by its abstraction:

```go
container.Make(func(a Abstraction) {
// a will be an concrete of Abstraction
})
```

For example:

```go
i.Make(func(r Repository) {
// r will be an instance of UserRepository
container.Make(func(m Mailer) {
m.Send("[email protected]", "Hello!")
})
```

Expand Down

0 comments on commit e22801a

Please sign in to comment.