GithubHelp home page GithubHelp logo

gioc's Introduction

简体中文

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

gioc's People

Contributors

vlorc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gioc's Issues

是不是可以发布一个版本

非常喜欢你的作品,只是在用 dep ensure -v -add github.com/vlorc/gioc 添加时总是没有任何反映,加过其它包到是成功过,然后看gioc没有 releases 过,所以想到这个原因,现在在用go get 获取了。。。先谢谢了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.