Skip to content

Commit

Permalink
updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Oct 27, 2015
1 parent 6e53e7f commit 7e24507
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ A dependency injection library using struct tags.

- [Slack channel](https://gophers.slack.com/messages/go-modules/)

This project is currently alpha and subject to experimental change.

## Overview
This library simplifies the wiring of an application by injecting dependencies between modules.

Expand Down Expand Up @@ -43,8 +41,10 @@ Fields may be set normally prior to binding.
module := struct {
FieldA string 'provide:"provideMe"'
} {
FieldA: "providedValue"
FieldA: "value"
}
// or
module.FieldA = "value"
```

Modules implementing the *Provider* interface may set fields from the *Provide* method.
Expand All @@ -54,10 +54,11 @@ type module struct {
Func func() string 'provide:"provideMe"'
}
// Implements modules.Provider
func (m *Module) Provide() {
func (m *Module) Provide() error {
m.Func = func() string {
return = m.Field
}
return nil
}
```
The *Provide* method is called during binding. Injected fields have not yet necessarily been set when *Provide* is
Expand All @@ -72,6 +73,10 @@ type module struct {
FieldC complex128 'provide:"complexField" literal:"-1,1"'
}
```
Other built-in tag keys include:
- 'env' for environment variables
- 'file' for os.File handles, and decoding of txt, json, xml, and gob
- 'flag' for command line arguments

### Binders
Modules are bound using a *Binder*. Binders are created with the *NewBinder* function, which optionally
Expand All @@ -95,15 +100,15 @@ The functional option *Injectors* can be used to map tag keys (anything besides
third party *Injector*s.
```go
injectors := modules.Injectors(map[string]Injector{
"customTag": customTag.Injector,
"customTag": customInjector,
})
binder := modules.NewBinder(injectors)
module := struct{
FieldA CustomType 'provide:"someField" customTag:"tagValueArgument"'
}
_ := binder.Bind(module)
```
When this module is bound, *customTag.Injector* may set the value of FieldA based on the tag value "tagValueArgument".
When this module is bound, *customInjector* may set the value of FieldA based on the tag value "tagValueArgument".

The *Injector* interface is defined in the inject package.
```go
Expand Down

0 comments on commit 7e24507

Please sign in to comment.