...

Text file src/github.com/codegangsta/inject/README.md

Documentation: github.com/codegangsta/inject

     1# inject
     2--
     3    import "github.com/codegangsta/inject"
     4
     5Package inject provides utilities for mapping and injecting dependencies in
     6various ways.
     7
     8Language Translations:
     9* [简体中文](translations/README_zh_cn.md)
    10
    11## Usage
    12
    13#### func  InterfaceOf
    14
    15```go
    16func InterfaceOf(value interface{}) reflect.Type
    17```
    18InterfaceOf dereferences a pointer to an Interface type. It panics if value is
    19not an pointer to an interface.
    20
    21#### type Applicator
    22
    23```go
    24type Applicator interface {
    25	// Maps dependencies in the Type map to each field in the struct
    26	// that is tagged with 'inject'. Returns an error if the injection
    27	// fails.
    28	Apply(interface{}) error
    29}
    30```
    31
    32Applicator represents an interface for mapping dependencies to a struct.
    33
    34#### type Injector
    35
    36```go
    37type Injector interface {
    38	Applicator
    39	Invoker
    40	TypeMapper
    41	// SetParent sets the parent of the injector. If the injector cannot find a
    42	// dependency in its Type map it will check its parent before returning an
    43	// error.
    44	SetParent(Injector)
    45}
    46```
    47
    48Injector represents an interface for mapping and injecting dependencies into
    49structs and function arguments.
    50
    51#### func  New
    52
    53```go
    54func New() Injector
    55```
    56New returns a new Injector.
    57
    58#### type Invoker
    59
    60```go
    61type Invoker interface {
    62	// Invoke attempts to call the interface{} provided as a function,
    63	// providing dependencies for function arguments based on Type. Returns
    64	// a slice of reflect.Value representing the returned values of the function.
    65	// Returns an error if the injection fails.
    66	Invoke(interface{}) ([]reflect.Value, error)
    67}
    68```
    69
    70Invoker represents an interface for calling functions via reflection.
    71
    72#### type TypeMapper
    73
    74```go
    75type TypeMapper interface {
    76	// Maps the interface{} value based on its immediate type from reflect.TypeOf.
    77	Map(interface{}) TypeMapper
    78	// Maps the interface{} value based on the pointer of an Interface provided.
    79	// This is really only useful for mapping a value as an interface, as interfaces
    80	// cannot at this time be referenced directly without a pointer.
    81	MapTo(interface{}, interface{}) TypeMapper
    82	// Provides a possibility to directly insert a mapping based on type and value.
    83	// This makes it possible to directly map type arguments not possible to instantiate
    84	// with reflect like unidirectional channels.
    85	Set(reflect.Type, reflect.Value) TypeMapper
    86	// Returns the Value that is mapped to the current type. Returns a zeroed Value if
    87	// the Type has not been mapped.
    88	Get(reflect.Type) reflect.Value
    89}
    90```
    91
    92TypeMapper represents an interface for mapping interface{} values based on type.

View as plain text