All Projects → workshop-depot → sector

workshop-depot / sector

Licence: MIT license
Simple Injector; Dependency Injection

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to sector

DI-compiler
A Custom Transformer for Typescript that enables compile-time Dependency Injection
Stars: ✭ 62 (+416.67%)
Mutual labels:  ioc, dependency-injection
stashbox
A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
Stars: ✭ 120 (+900%)
Mutual labels:  ioc, dependency-injection
Hiboot
hiboot is a high performance web and cli application framework with dependency injection support
Stars: ✭ 150 (+1150%)
Mutual labels:  ioc, dependency-injection
hypo-container
A dependency injection container.
Stars: ✭ 16 (+33.33%)
Mutual labels:  ioc, dependency-injection
Tsyringe
Lightweight dependency injection container for JavaScript/TypeScript
Stars: ✭ 2,761 (+22908.33%)
Mutual labels:  ioc, dependency-injection
Dry Auto inject
Container-agnostic constructor injection mixin
Stars: ✭ 149 (+1141.67%)
Mutual labels:  ioc, dependency-injection
Typedi
Simple yet powerful dependency injection tool for JavaScript and TypeScript.
Stars: ✭ 2,832 (+23500%)
Mutual labels:  ioc, dependency-injection
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+16075%)
Mutual labels:  ioc, dependency-injection
Typhoon
Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
Stars: ✭ 2,711 (+22491.67%)
Mutual labels:  ioc, dependency-injection
Qframework
Unity3D System Design Architecture
Stars: ✭ 2,326 (+19283.33%)
Mutual labels:  ioc, dependency-injection
Node Dependency Injection
The NodeDependencyInjection component allows you to standarize and centralize the way objects are constructed in your application.
Stars: ✭ 140 (+1066.67%)
Mutual labels:  ioc, dependency-injection
Dry System
Organize your code into reusable components
Stars: ✭ 228 (+1800%)
Mutual labels:  ioc, dependency-injection
Disco
PSR-11 compatible Dependency Injection Container for PHP.
Stars: ✭ 135 (+1025%)
Mutual labels:  ioc, dependency-injection
Testdeck
Object oriented testing
Stars: ✭ 206 (+1616.67%)
Mutual labels:  ioc, dependency-injection
React Ioc
Hierarchical Dependency Injection with new React 16 Context API
Stars: ✭ 133 (+1008.33%)
Mutual labels:  ioc, dependency-injection
Container
A lightweight yet powerful IoC container for Go projects
Stars: ✭ 160 (+1233.33%)
Mutual labels:  ioc, dependency-injection
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (+641.67%)
Mutual labels:  ioc, dependency-injection
Unity
This repository contains all relevant information about Unity Container suit
Stars: ✭ 1,513 (+12508.33%)
Mutual labels:  ioc, dependency-injection
Awilix
Extremely powerful Inversion of Control (IoC) container for Node.JS
Stars: ✭ 2,269 (+18808.33%)
Mutual labels:  ioc, dependency-injection
Ioc
🦄 lightweight (<1kb) inversion of control javascript library for dependency injection written in typescript
Stars: ✭ 171 (+1325%)
Mutual labels:  ioc, dependency-injection

sector

License MIT GoDoc Go Report Card Build Status codecov

sector - for Simple Injector - provides a Dependency Injection mechanism for Go.

Put it simply, sector fills pointers with values come from factories. So we have the factory - the constructor (role) - and the injector.

A factory implements the Factory interface. In it's simplest form, it's just a function with this signature, func(interface{}) bool and uses the Go's type switch to fill the pointers:

func myFactory(ptr interface{}) bool {
	switch x := ptr.(type) {
	case *int:
		*x = 1001
	case *string:
		*x = `injected string`
	case *Trait:
		buffer := Trait{}
		*x = buffer
	case *Data:
		buffer := Data{}
		*x = buffer
	case *map[string]interface{}:
		*x = make(map[string]interface{})
		(*x)[`asset`] = `another injected string`
	case *SI:
		v := SIO{`yet another injected string`}
		*x = &v
	case *[]int:
		*x = []int{1, 2, 3}
	default:
                // this factory does not fill pointers of this type
		return false
	}

	return true
}

Then we use this factory in our injector to fill in the fields of a struct.

dj := NewInjector(FactoryFunc(genericFactory))

Now we use this injector to inject desired values into struct's fields.

var s Sample
dj.Inject(&s)

Fields that are tagged with inject:"+" will get filled with proper value from the factory. Fields tagged with inject:"*" will get filled recursively down the tree.

type Sample struct {
	Trait `inject:"*"`      // inject field, recursively, all down the data tree  

	N  int    `inject:"+"`  // inject field
	S  string `inject:"+"`
	D  Data   `inject:"*"`
	NL []int  `inject:"+"`

	Map     map[string]interface{} `inject:"+"`
	DataPtr *Data                  `inject:"*"`

	SI SI `inject:"+"`
}

It is also possible to inject arguments of a function using the Invoke method.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].