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

Instance

Instance registers an existing value directly without any factory function. This is the simplest form of registration for values that are already created.

Key Points:

  • 📝 Registers an existing value directly
  • ⚠️ No concurrency protection (read-only recommended)
  • 🎯 Best for immutable values or configuration

Example

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

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

func init() {
	// Register a configuration value
	remy.Register(
		nil,
		remy.Instance("production"),
	)

	// Or use the convenience function
	remy.RegisterInstance(nil, 42)
	remy.RegisterInstance(nil, true)
}

⚠️ WARNING: Instance binds have no protection over concurrency, so they’re not recommended for structs that perform operations that modify their attributes. Use Singleton or LazySingleton for concurrent mutable binds.