box

package module
v0.0.0-...-c88784e Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: MIT Imports: 2 Imported by: 0

README

📦 Box - is your dependency helping hand

Build Status codecov

Usage

package main

import (
	"fmt"
	
	"github.com/cryptopay-dev/pony-box"
)

type A struct {}
type B struct {}

func (a A) Ping() string {
	return "ping"
}


func (b B) Pong() string {
	return "pong"
}

func main() {
    b := box.New()
    if err := b.Provide(
    	box.NewProvider(A{}), 
    	box.NewProvider(B{}),
    ); err != nil {
    	panic(err)
    }
    
    if err := b.Invoke(func(a A, b B) error {
    	fmt.Printf("%s - %s\n", a.Ping(), b.Pong())
    	return nil
    }); err != nil {
    	panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyProviders thrown when empty providers provided
	ErrEmptyProviders = errors.New("empty providers")
)

Functions

This section is empty.

Types

type Box

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

Box is handling dig container

func New

func New() Box

New creates new Box

func (Box) Invoke

func (b Box) Invoke(fn interface{}, opts ...dig.InvokeOption) error

Invoke run fn function with all it's dependencies trying to resolve them through box

func (Box) Provide

func (b Box) Provide(providers ...Provider) error

Provide setting up a list of providers inside a box, can throw ErrEmptyProviders when providers list is empty.

type Provider

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

Provider handles constructor fn and options provided

func NewProvider

func NewProvider(fn interface{}, opts ...dig.ProvideOption) Provider

NewProvider creates new provider that can be added to box

Jump to

Keyboard shortcuts

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