di

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Service structure.

To use:

1) Invoke `di.GetInstance` to access the singleton: ```go

svc := di.GetInstance

```

2a) Add your required service: ```go

svc.Add("SomeName", someInstance)

```

2b) Create your required service: ```go

svc.Create("SomeName", func() interface{} { return NewThing() })

```

func DumpInstance

func DumpInstance() *Service

Debugging aid -- do *not* use.

func GetInstance

func GetInstance() *Service

Return the service manager's singleton instance.

func (*Service) Add

func (s *Service) Add(name string, thing interface{})

Add a new service instance with the given name.

func (*Service) AddClass

func (s *Service) AddClass(name string, ctor ServiceCtorFn)

Add a new class with the given name.

func (*Service) Classes

func (s *Service) Classes() []string

Get a list of registered classes.

func (*Service) CountClasses

func (s *Service) CountClasses() int

Return a count of registered classes.

func (*Service) CountServices

func (s *Service) CountServices() int

Return a count of registered services.

func (*Service) CreateNew

func (s *Service) CreateNew(name string) (interface{}, bool)

Create a new instance of the given class by invoking its registered constructor.

func (*Service) Get

func (s *Service) Get(name string) (interface{}, bool)

Get a service with the given name.

func (*Service) Services

func (s *Service) Services() []string

Get a list of registered services.

type ServiceCtorFn

type ServiceCtorFn func() interface{}

Constructor function for creating new service records.

Jump to

Keyboard shortcuts

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