Skip to main content
Remy DI - Dependency Injection for Go
GitHub Go Docs Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Examples

Complete working examples are available in the examples directory of the GitHub repository.

Available Examples

  • basic - Basic usage example showing singleton registration and retrieval
  • bindlogger - How to inject loggers and other utilities
  • context_jwt_user - Context-aware retrieval and JWT claim mapping into a User dependency
  • dynamiconstructor - Dynamic constructor registration examples
  • guessing_types - Type guessing and interface examples

Each example is a complete, runnable Go program that demonstrates specific features of Remy DI.

Quick Example

Here’s a simple example to get you started:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package main

import (
	"log"
	"github.com/wrapped-owls/goremy-di/remy"
)

var Injector = remy.NewInjector()

func init() {
	remy.RegisterSingleton(Injector, func() (string, error) {
		return "Hello from Remy!", nil
	})
}

func main() {
	message := remy.MustGet[string](Injector)
	log.Println(message)
}

For more detailed examples, visit the examples directory on GitHub.