Skip to content

Latest commit

 

History

History

di

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Dependency Injection in Go

This is a simple RESTful API service. In the code, we are using dependency injection (DI) to load and initialize dependencies when starting the application.

3 ways to inject dependencies:

  • No DI framework - Basic DI implemented using Go, no third-party DI framework.
  • The Dig framework - Use the Dig framework to inject dependencies at runtime. See the example for details.
  • The Wire framework - Use the Wire framework to generate the DI code at compile time. See [the example] (cmd/wire) for details.

Setup

  1. Install the third party packages.

    $ make install
  2. You can run of the following targets corresponding to a DI framework.

    $ make run-no-framework
    $ make run-dig
    $ make run-wire
  3. On another shell.

    $ curl localhost:8000

Reference