ioc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ioc implements inversion of control containers and the dependency injection pattern. see https://martinfowler.com/articles/injection.html

Index

Constants

This section is empty.

Variables

View Source
var ErrHasRegistered = errors.New("ioc: type/instance has already been registered")

ErrHasRegistered 物件/實例已經被註冊

View Source
var ErrNoRegistered = errors.New("ioc: type/instance is not registered")

ErrNoRegistered 物件/實例未被註冊

Functions

func Register

func Register(ctx context.Context, name string, createNew CreateNew) error

Register 註冊物件

func RegisterInstance

func RegisterInstance(ctx context.Context, name string, instance interface{}) error

RegisterInstance 註冊全局的物件實例

func Resolve

func Resolve(ctx context.Context, name string) (interface{}, error)

Resolve 創建指定的名稱的物件新實例

func ResolveInstance

func ResolveInstance(ctx context.Context, name string) (interface{}, error)

ResolveInstance 獲取全局的物件實例

Types

type CreateNew

type CreateNew func(ctx context.Context) interface{}

CreateNew 購造新物件實例

Jump to

Keyboard shortcuts

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