framework

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container interface {
	// Bind 绑定一个服务提供者,如果关键字凭证已经存在,会进行替换操作,返回error
	Bind(provider ServiceProvider) error
	// IsBind 关键字凭证是否已经绑定服务提供者
	IsBind(key string) bool

	// Make 根据关键字凭证获取一个服务,
	Make(key string) (interface{}, error)
	// MustMake 根据关键字凭证获取一个服务,如果这个关键字凭证未绑定服务提供者,那么会panic。
	// 所以在使用这个接口的时候请保证服务容器已经为这个关键字凭证绑定了服务提供者。
	MustMake(key string) interface{}
	// MakeNew 根据关键字凭证获取一个服务,只是这个服务并不是单例模式的
	// 它是根据服务提供者注册的启动函数和传递的params参数实例化出来的
	// 这个函数在需要为不同参数启动不同实例的时候非常有用
	MakeNew(key string, params []interface{}) (interface{}, error)
}

Container 是一个服务容器,提供绑定服务和获取服务的功能

type HadeContainer

type HadeContainer struct {
	Container
	// contains filtered or unexported fields
}

HadeContainer 是服务容器的具体实现

func NewHadeContainer

func NewHadeContainer() *HadeContainer

NewHadeContainer 创建一个服务容器

func (*HadeContainer) Bind

func (hade *HadeContainer) Bind(provider ServiceProvider) error

Bind 将服务容器和关键字做了绑定

func (*HadeContainer) IsBind

func (hade *HadeContainer) IsBind(key string) bool

func (*HadeContainer) Make

func (hade *HadeContainer) Make(key string) (interface{}, error)

func (*HadeContainer) MakeNew

func (hade *HadeContainer) MakeNew(key string, params []interface{}) (interface{}, error)

func (*HadeContainer) MustMake

func (hade *HadeContainer) MustMake(key string) interface{}

func (*HadeContainer) NameList added in v0.0.2

func (hade *HadeContainer) NameList() []string

NameList 列出容器中所有服务提供者的字符串凭证

func (*HadeContainer) PrintProviders added in v0.0.2

func (hade *HadeContainer) PrintProviders() []string

PrintProviders 输出服务容器中注册的关键字

type NewInstance

type NewInstance func(...interface{}) (interface{}, error)

NewInstance 定义了如何创建一个新实例,所有服务容器的创建服务

type ServiceProvider

type ServiceProvider interface {
	// Register 在服务容器中注册了一个实例化服务的方法,是否在注册的时候就实例化这个服务,需要参考IsDefer接口。
	Register(Container) NewInstance
	// Boot 在调用实例化服务的时候会调用,可以把一些准备工作:基础配置,初始化参数的操作放在这个里面。
	// 如果Boot返回error,整个服务实例化就会实例化失败,返回错误
	Boot(Container) error
	// IsDefer 决定是否在注册的时候实例化这个服务,如果不是注册的时候实例化,那就是在第一次make的时候进行实例化操作
	// false表示不需要延迟实例化,在注册的时候就实例化。true表示延迟实例化
	IsDefer() bool
	// Params params定义传递给NewInstance的参数,可以自定义多个,建议将container作为第一个参数
	Params(Container) []interface{}
	// Name 代表了这个服务提供者的凭证
	Name() string
}

ServiceProvider 定义一个服务提供者需要实现的接口

Directories

Path Synopsis
doc
gin
Package gin implements a HTTP web framework called gin.
Package gin implements a HTTP web framework called gin.
provider
app
env
id
log
orm
sls
ssh

Jump to

Keyboard shortcuts

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