iocgo

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

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

README

iocgo

An IOC container in Golang

This project is inspired by the IOC-Golang and K8S controller-tools projects

Design ideas

1.BeanDefinition

  • bean name

  • scope

  • autowire enabled

  • configuration struct

  • factory func

  • init func

  • destroy func

  • description

  • // +ioc:autowired:beandefinition  // mark a beandefinition
    
    type DumpyBeanDefinition struct {
    	Name              string      // bean name
    	Scope             scope.Scope // scope of bean
    	AutowireCandidate bool        // autowire enabled
    	Configuration     string      // configuration struct
    	FactoryFunc       string      // factory func
    	InitFunc          string      // init func
    	DestroyFunc       string      // destroy func
    	Description       string      // description of bean
    }
    

2.BeanFactory

  • Register
  • GetBean
  • Destroy

3.LifeCycle

  • InitializingBean
    • AfterPropertiesSet()
  • DisposableBean
    • Destroy()

4.Configuration

// +ioc:autowired:factorybean // mark a bean is a factory bean

type Person struct {
ID   int64  `json:"id"`
Name string `json:"name"`
Age  uint8  `json:"age"`
}

// +ioc:autowired:configuration // mark a configuration struct -> @Configuration
type PersonConfiguration struct {
}

// +ioc:autowired:factoryfunc // mark a func is configuration factory func -> @Bean
// +ioc:autowired:scope=singleton // mark a bean scope is singleton

func (config *PersonConfiguration) CreatePerson(ctx context.Context) Person {
return Person{
ID:   9527,
Name: "photowey",
Age:  18,
}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start()

Start - start the IOC container.

Types

This section is empty.

Jump to

Keyboard shortcuts

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