ice

package
v0.0.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

ice is a lightweight Dependency Injection Framework

ice's cenral metaphor is a "Magic Bag".

It's a Bag because you put things in and then take things out.

Imagine a bag where you put in building materials and an Ikea instruction manual, and then you pull out a fully-formed desk. The bag did the assembly! Magic!

ice works not with Noric flat pack furniture but with Go. Our object graph is composed of Go values (the nodes) and Providers (the edges).

Lifecycle

  1. Create an Empty Bag
  2. Insert Provider Functions a) or a Module, which can insert many Provider at once
  3. Extract Values

Terms

Key: what ice knows how to create. Currently a Go type, but this may be extended.

Provider: a function that creates a foo. It may either return foo or (foo, error).

Magic Bag: binds Keys to Providers.

Extract: Use the bindings in a Magic Bag to create and wire together complex structs

Module: utility to install multiple Providers at once

Notes

ice uses reflection heavily.

(MagicBag in ice is the equivalent of Guice's Injector or Dagger 1's ObjectGraph)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InjectionError

type InjectionError struct {
	// contains filtered or unexported fields
}

func (*InjectionError) Error

func (e *InjectionError) Error() string

func (*InjectionError) String

func (e *InjectionError) String() string

type Key

type Key reflect.Type

type MagicBag

type MagicBag struct {
	// contains filtered or unexported fields
}

MagicBag binds Providers to Keys which an Evaluation can use

func NewMagicBag

func NewMagicBag() *MagicBag

func (*MagicBag) Bindings

func (b *MagicBag) Bindings() map[Key]Provider

func (*MagicBag) Extract

func (bag *MagicBag) Extract(dest interface{}) (result error)

Extract extracts a value from the MagicBag and puts it into dest, returning any errors dest must be a pointer to a type this MagicBag knows how to construct.

func (*MagicBag) InstallModule

func (e *MagicBag) InstallModule(m Module) error

func (*MagicBag) Put

func (b *MagicBag) Put(f interface{})

func (*MagicBag) PutMany

func (b *MagicBag) PutMany(fs ...interface{})

type Module

type Module interface {
	Install(b *MagicBag)
}

Module can install many things at once. It could be just []Provider, but this lets Module code look a little nicer,

type Provider

type Provider interface{}

type Value

type Value reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL