Categorygithub.com/vlorc/gioc
repositorypackage
1.0.3
Repository: https://github.com/vlorc/gioc.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Gioc

简体中文

License codebeat badge Go Report Card GoDoc Build Status Coverage Status

gioc is a lightweight Ioc framework,it provides register and factory and depend solution

Features

  • Dependency Resolve
  • Dependency Inject
  • Singleton/Transient Support
  • Custom Tag
  • Invoker Support
  • Lazy Load
  • Struct Extends Support
  • Condition Support
  • Module Support

Installing

go get -u github.com/vlorc/gioc

Quick Start

  • Create Root Module
gioc.NewRootModule()
  • Import Module
NewModuleFactory(
    Import(
        ConfigModule,
        ServerModule,
    )
)
  • Declare Instance
NewModuleFactory(
    Declare(
        Instance(1), Id("id"),
        Instance("ioc"), Id("name"),
    ),
)
  • Export Instance
NewModuleFactory(
    Export(
        Instance(1), Id("id"),
        Instance("ioc"), Id("name"),
    ),
)
  • Condition Import
NewModuleFactory(
    Condition(
    	HavingValue(Equal("redis"), types.StringType, "cache.type"), 
    	Import(RedisModule),
    ),
    Condition(
        Or(
            Not(HavingBean(types.StringType, "cache.type")),
            HavingValue(Equal("memory"), types.StringType, "cache.type"),
        ), 
        Import(MemoryModule),
    ),
)

Examples

  • Basic Module
import (
    ."github.com/vlorc/gioc"
    ."github.com/vlorc/gioc/module"
    ."github.com/vlorc/gioc/module/operation"
)

// config.go
var ConfigModule = NewModuleFactory(
    Export(
        Mapping(map[string]interface{}{
            "id": 1,
            "name": "ioc",
        }),
    ),
)

// main.go
func main() {
    NewRootModule(
        Import(ConfigModule),
        Bootstrap(func(param struct{ id int; name string }) {
            println("id: ", param.id, " name: ",param.name)
        }),
    )
}

License

This project is under the apache License. See the LICENSE file for the full license text.

Interface

  • Provider
    • provides Factory discovery
  • Factory
    • responsible for generating Instance
    • the basic plant has a value factory, method factory, agent factory, single factory, type factory
  • Register
    • as a connection to Factory and Selector
    • provides the registration method, which eventually matches the Type to the Factory
  • Dependency
    • for target type dependency analysis, collection integration
    • converted to an Injector by an instance
  • Container
    • provides Register and Provider, and the parent container makes up traversal
    • convert to read-only Provider
    • convert to seal Container
  • Selector
    • find factory by type and name
  • Module
    • import module
    • export factory
    • declare factory

Roadmap

For details on planned features and future direction please refer to roadmap

Keyword

dependency injection, inversion of control

Reference