container

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 4 Imported by: 0

README

giocamole

Go ioc container

Modified version of github.com/golobby/container/v3

Installation

To install this package, run the following command in your project directory.

go get github.com/ClementLaval/giocamole

Additional method:

// DeepFill recursively injects dependencies into the target struct.
// You can also provide additional direct dependencies as a second argument (a struct pointer).
// The container will prioritize injecting the provided direct dependencies over those in the container.
// This is useful for passing temporary dependencies, such as (w, *r, session).
func DeepFill(structure interface{}, dependencies interface{}) error {}

Documentation

Overview

Package container is a lightweight yet powerful IoC container for Go projects. It provides an easy-to-use interface and performance-in-mind container to be your ultimate requirement.

Index

Constants

This section is empty.

Variables

View Source
var Global = New()

Global is the global concrete of the Container.

Functions

func Call

func Call(receiver interface{}) error

Call calls the same method of the global concrete.

func DeepFill

func DeepFill(receiver interface{}, dependencies *interface{}) error

func Fill

func Fill(receiver interface{}) error

Fill calls the same method of the global concrete.

func MustCall

func MustCall(c Container, receiver interface{})

MustCall wraps the `Call` method and panics on errors instead of returning the errors.

func MustDeepFill

func MustDeepFill(c Container, receiver interface{}, dependencies interface{})

MustDeepFill wraps the `Fill` method and panics on errors instead of returning the errors.

func MustFill

func MustFill(c Container, receiver interface{})

MustFill wraps the `Fill` method and panics on errors instead of returning the errors.

func MustNamedResolve

func MustNamedResolve(c Container, abstraction interface{}, name string)

MustNamedResolve wraps the `NamedResolve` method and panics on errors instead of returning the errors.

func MustNamedSingleton

func MustNamedSingleton(c Container, name string, resolver interface{})

MustNamedSingleton wraps the `NamedSingleton` method and panics on errors instead of returning the errors.

func MustNamedSingletonLazy

func MustNamedSingletonLazy(c Container, name string, resolver interface{})

MustNamedSingleton wraps the `NamedSingletonLazy` method and panics on errors instead of returning the errors.

func MustNamedTransient

func MustNamedTransient(c Container, name string, resolver interface{})

MustNamedTransient wraps the `NamedTransient` method and panics on errors instead of returning the errors.

func MustNamedTransientLazy

func MustNamedTransientLazy(c Container, name string, resolver interface{})

MustNamedTransient wraps the `NamedTransientLazy` method and panics on errors instead of returning the errors.

func MustResolve

func MustResolve(c Container, abstraction interface{})

MustResolve wraps the `Resolve` method and panics on errors instead of returning the errors.

func MustSingleton

func MustSingleton(c Container, resolver interface{})

MustSingleton wraps the `Singleton` method and panics on errors instead of returning the errors.

func MustSingletonLazy

func MustSingletonLazy(c Container, resolver interface{})

MustSingleton wraps the `SingletonLazy` method and panics on errors instead of returning the errors.

func MustTransient

func MustTransient(c Container, resolver interface{})

MustTransient wraps the `Transient` method and panics on errors instead of returning the errors.

func MustTransientLazy

func MustTransientLazy(c Container, resolver interface{})

MustTransientLazy wraps the `TransientLazy` method and panics on errors instead of returning the errors.

func NamedResolve

func NamedResolve(abstraction interface{}, name string) error

NamedResolve calls the same method of the global concrete.

func NamedSingleton

func NamedSingleton(name string, resolver interface{}) error

NamedSingleton calls the same method of the global concrete.

func NamedSingletonLazy

func NamedSingletonLazy(name string, resolver interface{}) error

NamedSingletonLazy calls the same method of the global concrete.

func NamedTransient

func NamedTransient(name string, resolver interface{}) error

NamedTransient calls the same method of the global concrete.

func NamedTransientLazy

func NamedTransientLazy(name string, resolver interface{}) error

NamedTransientLazy calls the same method of the global concrete.

func Reset

func Reset()

Reset calls the same method of the global concrete.

func Resolve

func Resolve(abstraction interface{}) error

Resolve calls the same method of the global concrete.

func Singleton

func Singleton(resolver interface{}) error

Singleton calls the same method of the global concrete.

func SingletonLazy

func SingletonLazy(resolver interface{}) error

SingletonLazy calls the same method of the global concrete.

func Transient

func Transient(resolver interface{}) error

Transient calls the same method of the global concrete.

func TransientLazy

func TransientLazy(resolver interface{}) error

TransientLazy calls the same method of the global concrete.

Types

type Container

type Container map[reflect.Type]map[string]*binding

Container holds the bindings and provides methods to interact with them. It is the entry point in the package.

func New

func New() Container

New creates a new concrete of the Container.

func (Container) Call

func (c Container) Call(function interface{}) error

Call takes a receiver function with one or more arguments of the abstractions (interfaces). It invokes the receiver function and passes the related concretes.

func (Container) DeepFill

func (c Container) DeepFill(structure interface{}, dependencies interface{}) error

DeepFill recursively injects dependencies into the target struct. You can also provide additional direct dependencies as a second argument (a struct pointer). The container will prioritize injecting the provided direct dependencies over those in the container. This is useful for passing temporary dependencies, such as (w, *r, session).

func (Container) Fill

func (c Container) Fill(structure interface{}) error

Fill takes a struct and resolves the fields with the tag `container:"inject"`

func (Container) NamedResolve

func (c Container) NamedResolve(abstraction interface{}, name string) error

NamedResolve takes abstraction and its name and fills it with the related concrete.

func (Container) NamedSingleton

func (c Container) NamedSingleton(name string, resolver interface{}) error

NamedSingleton binds a named abstraction to concrete in singleton mode.

func (Container) NamedSingletonLazy

func (c Container) NamedSingletonLazy(name string, resolver interface{}) error

NamedSingleton binds a named abstraction to concrete lazily in singleton mode. The concrete is resolved only when the abstraction is resolved for the first time.

func (Container) NamedTransient

func (c Container) NamedTransient(name string, resolver interface{}) error

NamedTransient binds a named abstraction to concrete lazily in transient mode.

func (Container) NamedTransientLazy

func (c Container) NamedTransientLazy(name string, resolver interface{}) error

NamedTransient binds a named abstraction to concrete in transient mode. Normally the resolver will be called during registration, but that is skipped in lazy mode.

func (Container) Reset

func (c Container) Reset()

Reset deletes all the existing bindings and empties the container.

func (Container) Resolve

func (c Container) Resolve(abstraction interface{}) error

Resolve takes an abstraction (reference of an interface type) and fills it with the related concrete.

func (Container) Singleton

func (c Container) Singleton(resolver interface{}) error

Singleton binds an abstraction to concrete in singleton mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.

func (Container) SingletonLazy

func (c Container) SingletonLazy(resolver interface{}) error

SingletonLazy binds an abstraction to concrete lazily in singleton mode. The concrete is resolved only when the abstraction is resolved for the first time. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.

func (Container) Transient

func (c Container) Transient(resolver interface{}) error

Transient binds an abstraction to concrete in transient mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.

func (Container) TransientLazy

func (c Container) TransientLazy(resolver interface{}) error

TransientLazy binds an abstraction to concrete lazily in transient mode. Normally the resolver will be called during registration, but that is skipped in lazy mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.

Jump to

Keyboard shortcuts

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