ioc

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: MIT Imports: 6 Imported by: 8

README

IOC

The IOC library is a dependency injection and management tool implemented in Golang.

Features:

  • Dependency Injection: Simplifies object creation and management using the ioc library.
  • Named Providers: Uses named providers to create and manage the same type of object.
  • Health Checks: Integrates health check functionality to ensure the health status of system components.

Installation

go get github.com/aiechoic/ioc

Provider

A Provider is a component responsible for creating instances of a specific type.

package main

import (
	"github.com/aiechoic/ioc"
)

type Engine struct{ Name string }

var engineProvider = ioc.NewProvider(func(c *ioc.Container) (*Engine, error) {
	engine := &Engine{}
	return engine, nil
})

Container

A Container is a central registry that stores singleton objects.

func main() {
    c := ioc.NewContainer()
    var engine *Engine = engineProvider.Get(c)
}

more examples can be found in the examples directory.

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

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

func NewContainer

func NewContainer() *Container

func (*Container) CheckHealth

func (c *Container) CheckHealth(ctx context.Context) []*healthy.Error

func (*Container) Close

func (c *Container) Close() error

func (*Container) CloseWithContext

func (c *Container) CloseWithContext(ctx context.Context) error

func (*Container) OnClose

func (c *Container) OnClose(closer func() error)

func (*Container) OnHealthCheck

func (c *Container) OnHealthCheck(checker func() *healthy.Error)

func (*Container) RunHealthCheck

func (c *Container) RunHealthCheck(ticker, timeout time.Duration, handler func(errs []*healthy.Error))

type MultiError

type MultiError []error

func (MultiError) Error

func (m MultiError) Error() string

type Provider

type Provider[T any] struct {
	// contains filtered or unexported fields
}

func NewProvider

func NewProvider[T any](new func(c *Container) (*T, error)) *Provider[T]

func (*Provider[T]) Get

func (f *Provider[T]) Get(c *Container) (t *T, err error)

func (*Provider[T]) GetNew

func (f *Provider[T]) GetNew(c *Container) (*T, error)

func (*Provider[T]) MustGet

func (f *Provider[T]) MustGet(c *Container) *T

func (*Provider[T]) MustGetNew

func (f *Provider[T]) MustGetNew(c *Container) *T

func (*Provider[T]) MustRefresh

func (f *Provider[T]) MustRefresh(c *Container) *T

func (*Provider[T]) Refresh

func (f *Provider[T]) Refresh(c *Container) (ins *T, err error)

func (*Provider[T]) Set

func (f *Provider[T]) Set(c *Container, ins *T)

type Providers

type Providers[T any] struct {
	// contains filtered or unexported fields
}

func NewProviders

func NewProviders[T any]() *Providers[T]

func (*Providers[T]) GetProvider

func (r *Providers[T]) GetProvider(name string, newPvd func() *Provider[T]) *Provider[T]

Directories

Path Synopsis
examples
healthy command
named_provider command
simple command

Jump to

Keyboard shortcuts

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