Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

IOC-golang

> 编程语言
Open source

一款服务于 Go 开发者的依赖注入框架,方便搭建任何 Go 应用。 A Golang depenedency injection framework, helps developers to build any go application.

1.2K stars0 likes1 views
WebsiteGitHub

About

IOC-golang: A golang dependency injection framework

  ___    ___     ____                           _                         
 |_ _|  / _ \   / ___|           __ _    ___   | |   __ _   _ __     __ _ 
  | |  | | | | | |      _____   / _` |  / _ \  | |  / _` | | '_ \   / _` |
  | |  | |_| | | |___  |_____| | (_| | | (_) | | | | (_| | | | | | | (_| |
 |___|  \___/   \____|          \__, |  \___/  |_|  \__,_| |_| |_|  \__, |
                                |___/                               |___/ 

English | 中文

IOC-golang is a powerful golang dependency injection framework that provides a complete implementation of IoC containers. Its capabilities are as follows:

Dependency Injection

  • Supports dependency injection of any structure and interface, we also support object life cycle management mechanism

  • Can take over object creation, parameter injection, factory methods. Customizable object parameter source

Struct Proxy

  • Based on the idea of AOP, we provide struct proxy layer for all struct registered to ioc-golang. In the scene of interface oriented development, we can use many devlops features based on the extenablility of this proxy AOP layer. Such as interface listing, param value watching, method level tracing, performance badpoint analysis, fault injection, method level tracing in distributed system and so on.

Automatic struct descriptor codes generation capability

  • We provide a code generation tool, and developers can annotate the structure through annotations, so as to easily generate structure registration code.

Scalability

  • Support the extension of struct to be injected, the extension of autowire model, and the extension of the debug AOP layer.

Many pre-defined components

  • Provides pre-defined objects and middleware sdk for injection directly.

Project Structure

  • aop: Debug module: Provide debugging API, provide debugging injection layer basic implementation and extendable API.
  • autowire: Provides two basic injection models: singleton model and multi-instance model
  • config: Configuration loading module, responsible for parsing ion-golang's configuration files
  • extension: Component extension directory: Provides preset implementation structures based on various domain. Such as database, cache, pubs.
  • example: example repository
  • iocli: code generation/program debugging tool

Quick start

Install code generation tools

bash
% go install github.com/alibaba/ioc-golang/[email protected]
% iocli
hello

Dependency Injection Tutorial

We will develop a project with the following topology, This tutorial can show:

  1. Registry codes generation
  2. Interface injection
  3. Struct pointer injection
  4. Get object by API
  5. Debug capability, list interface, implementations and methods; watch real-time param and return value.

All the code the user needs to write: main.go

…

The proxy wrapped layer mentioned above, is a proxy layer injected by ioc-golang by default, when developer want to inject an object to interface field, or get with interface by API. Inject to interface is recommended by us. Every object injected with proxy wrapped layer would have devops feature.

After writing, you can exec the following cli command to init go mod and generate codes. (mac may require sudo due to permissions during code generation)

bash
% go mod init ioc-golang-demo
% export GOPROXY="https://goproxy.cn"
% go mod tidy
% go get github.com/alibaba/ioc-golang@master
% sudo iocli gen

It will be generated in the current directory: zz_generated.ioc.go, developers do not need to care about this file, 'GetAppSingleton' method mentioned above is defined in generated code.

…

See the file tree:

bash
% tree
.
├── go.mod
├── go.sum
├── main.go
└── zz_generated.ioc.go

0 directories, 4 files

Execute program

go run .

Console printout:

…

It shows that the injection is successful and the program runs normally.

Debug the app

Following logs can be found in console output:

bash
[Debug] Debug server listening at :1999

Open a new console, use iocli 's debug feature to list all structs with proxy layer, and their methods. Default port is 1999.

% iocli list
main.ServiceImpl1
[GetHelloString]

main.ServiceImpl2
[GetHelloString]

Watch real-time param and return value. We take main.ServiceImpl 's 'GetHelloString' method as an example. The method would be called twice every 3s :

bash
% iocli watch main.ServiceImpl1 GetHelloString
========== On Call ==========
main.ServiceImpl1.GetHelloString()
Param 1: (string) (len=8) "laurence"

========== On Response ==========
main.ServiceImpl1.GetHelloString()
Response 1: (string) (len=36) "This is ServiceImpl1, hello laurence"

========== On Call ==========
main.ServiceImpl1.GetHelloString()
Param 1: (string) (len=8) "laurence"

========== On Response ==========
main.ServiceImpl1.GetHelloString()
Response 1: (string) (len=36) "This is ServiceImpl1, hello laurence"
...

Annotation Analysis

go
// +ioc:autowire=true
The code generation tool recognizes objects marked with the +ioc:autowire=true annotation

// +ioc:autowire:type=singleton
The marker autowire model is the singleton

More

Docs

More code generation annotations can be viewed at iocli.

You can go to ioc-golang/example for more examples and advanced usage.

You can go to E-commercial system demo based on ioc-golang to refer to applications system on distributed scene.

License

IOC-golang developed by Alibaba and licensed under the Apache License (Version 2.0). See the NOTICE file for more information.

Connect with us

Welcome to join dingtalk group 44638289 if you are interested with the project.

Star me please ⭐

If you think this project is interesting, or helpful to you, please give a star!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goannotationaopdebugdependency-injection

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言