• Stars
    star
    985
  • Rank 46,289 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dependency injection for go

inject

-- import "github.com/codegangsta/inject"

Package inject provides utilities for mapping and injecting dependencies in various ways.

Language Translations:

Usage

func InterfaceOf

func InterfaceOf(value interface{}) reflect.Type

InterfaceOf dereferences a pointer to an Interface type. It panics if value is not an pointer to an interface.

type Applicator

type Applicator interface {
	// Maps dependencies in the Type map to each field in the struct
	// that is tagged with 'inject'. Returns an error if the injection
	// fails.
	Apply(interface{}) error
}

Applicator represents an interface for mapping dependencies to a struct.

type Injector

type Injector interface {
	Applicator
	Invoker
	TypeMapper
	// SetParent sets the parent of the injector. If the injector cannot find a
	// dependency in its Type map it will check its parent before returning an
	// error.
	SetParent(Injector)
}

Injector represents an interface for mapping and injecting dependencies into structs and function arguments.

func New

func New() Injector

New returns a new Injector.

type Invoker

type Invoker interface {
	// Invoke attempts to call the interface{} provided as a function,
	// providing dependencies for function arguments based on Type. Returns
	// a slice of reflect.Value representing the returned values of the function.
	// Returns an error if the injection fails.
	Invoke(interface{}) ([]reflect.Value, error)
}

Invoker represents an interface for calling functions via reflection.

type TypeMapper

type TypeMapper interface {
	// Maps the interface{} value based on its immediate type from reflect.TypeOf.
	Map(interface{}) TypeMapper
	// Maps the interface{} value based on the pointer of an Interface provided.
	// This is really only useful for mapping a value as an interface, as interfaces
	// cannot at this time be referenced directly without a pointer.
	MapTo(interface{}, interface{}) TypeMapper
	// Provides a possibility to directly insert a mapping based on type and value.
	// This makes it possible to directly map type arguments not possible to instantiate
	// with reflect like unidirectional channels.
	Set(reflect.Type, reflect.Value) TypeMapper
	// Returns the Value that is mapped to the current type. Returns a zeroed Value if
	// the Type has not been mapped.
	Get(reflect.Type) reflect.Value
}

TypeMapper represents an interface for mapping interface{} values based on type.

More Repositories

1

gin

Live reload utility for Go web servers
Go
4,228
star
2

martini-contrib

This project has moved!
Go
278
star
3

bwag

Source code for the book "Building Web Apps with Go"
Go
197
star
4

essential-go

Go
174
star
5

caddy-nats

A caddy module that adds support for nats.io pub/sub and request/reply
Go
85
star
6

mixer

Classy HTTP Handlers in Go
Go
57
star
7

dotfiles

Jeremy's dotfiles
Shell
53
star
8

controller

Lightweight Web Controllers in Go
Go
27
star
9

envy

General purpose environment bootstrapper
Go
25
star
10

go-advent-martini

Example project for the Go Advent Martini post
Go
22
star
11

mixology

A small, idiomatic http routing library for Go
Go
17
star
12

attr_inject

Elegant dependency injection in ruby
Ruby
16
star
13

schema_registry

A Bare bones and barely working schema registry for NATS
Go
9
star
14

pompom

Go
6
star
15

codegangsta.github.io

Rants and raves from a certified G
Astro
5
star
16

hip

A console buddy for your http requests.
Go
5
star
17

Astroneer

A mod for Starfield that puts you in the shoes of a freelance ship designer.
CUE
4
star
18

confab

Anonymized email service
Go
4
star
19

context-helpers

Go
4
star
20

goget

Serving up go package versions since 2014
Go
4
star
21

gophercon_2023_workshop

Go
3
star
22

PBTriggers

A simple but powerful trigger implementation for Pushbutton Engine
ActionScript
3
star
23

ck3_language_server

A Language Server Protocol (LSP) implementation of the Paradox interactive scripting language for Crusader Kings 3
Go
2
star
24

viewcontroller

Go
2
star
25

deck

Slide decks for presentations and workshops
MDX
2
star
26

ImbueSharp

A Simple dependency injection system for C#
C#
2
star
27

imbue.js

Dead simple dependency injection for javascript
JavaScript
2
star
28

alfred-teamocil

A teamocil launcher for Alfred
Ruby
2
star
29

negroni-docker-test

Go
1
star
30

MetaUtil

AS3 utility for easily processing metadata
ActionScript
1
star
31

s3_thumbnail

Ruby
1
star
32

Budgey

iPhone app using the Fiscus API
Objective-C
1
star
33

kubecon22

Kubecon 2022 slides and example
1
star
34

spotify

Go bindings for libspotify
Go
1
star
35

billboard

Cool terminal display for things like time and stats
C
1
star
36

firekeeper

TypeScript
1
star
37

nats-todo

TypeScript
1
star
38

nats-trivia

TypeScript
1
star