Skip to main content

Package loading

Package loading groups multiple service registrations.

Registration

The services can be assembled into a package, and then, exported all at once.

package stores

var Package = do.Package(
do.Lazy(NewPostgreSQLConnectionService),
do.Lazy(NewUserRepository),
do.Lazy(NewArticleRepository),
)

Play: https://go.dev/play/p/kmf8aOVyj96

The traditional vocab can be translated for package registration:

  • Provide[T](Injector, Provider[T]) -> Lazy(Provider[T])
  • ProvideNamed[T](Injector, string, Provider[T]) -> LazyNamed(string, Provider[T])
  • ProvideValue(Injector, T) -> Eager(T)
  • ProvideNamedValue[T](Injector, string, T) -> EagerNamed(string, T)
  • ProvideTransient[T](Injector, Provider[T]) -> Transient(Provider[T])
  • ProvideNamedTransient[T](Injector, string, Provider[T]) -> TransientNamed(string, Provider[T])
  • As[Initial, Alias](Injector) -> Bind[Initial, Alias]()
  • AsNamed[Initial, Alias](Injector, string, string) -> BindNamed[Initial, Alias](string, string)