di

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package di is a wrapper of fx, which allows to use DI across the whole lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

func Extract(target interface{})

Extract an injected object to a variable.

For example, we can extrat injected `Some` object to a global variable:

type globals struct {
	some *Some
}

var g = &globals{};

func init() {
	di.Extract(&g);
}

func Invoke

func Invoke(fn interface{})

Invoke a function with injected objects as parameters.

For example, we want use `Some` object:

func init() {
   di.Invoke(func(s *Some) {
       // -- snip --
   })
}

func InvokeBefore

func InvokeBefore(fn interface{})

InvokeBefore invoke the given function before others.

func Options

func Options() []fx.Option

Options of current project.

func Populate

func Populate(targets ...interface{})

Populate allows to extract multiple injected objects to variables.

func Provide

func Provide(newFn interface{})

Provide a constructor method to create object for injection purpose.

For example, we are going to inject `Some`:

type Some struct {
  // -- snip --
}

func newSome() *Some {
  // -- snip --
}

func init() {
    di.Provide(newSome)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL