An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

github.com/logrange/linker

Package linker provides Dependency Injection and Inversion of Control functionality. The core component is Injector, which allows to register Components. Component is an object, which can have any type, which requires some initialization, or can be used for initializing other components. Every component is registered in the Injector by the component name or anonymously (empty name). Same object can be registered by different names. This could be useful if the object implements different interfaces that can be used by different components. The package contains several interfaces: PostConstructor, Initializer and Shutdowner, which could be implemented by components with a purpose to be called by Injector on different initialization/de-initialization phases. Init() function of Injector allows to initialize registered components. The initialization process supposes that components with 'pointer to struct' type or interfaces, which contains a 'pointer to struct' will be initialized. The initialization supposes to inject (assign) the struct fields values using other registered components. Injector matches them by name or by type. Injector uses fail-fast strategy so any error is considered like misconfiguraion and a panic happens. When all components are initialized, the components, which implement PostConstructor interface will be notified via PostConsturct() function call. The order of PostConstruct() calls is not defined. After the construction phase, injector builds dependencies graph with a purpose to detect dependency loops and to establish components initialization order. If a dependency loop is found, Injector will panic. Components, which implement Initializer interface, will be notified in specific order by Init(ctx) function call. Less dependant components will be initialized before the components that have dependency on the first ones. Injector is supposed to be called from one go-routine and doesn't support calls from multiple go-routines. Initialization process could take significant time, so context is provided. If the context is cancelled or closed it will be detected either by appropriate component or by the Injector what will cause of de-intializing already initialized components using Shutdown() function call (if provided) in reverse of the initialization order. Panic will happen then.

Ecosystem
proxy.golang.org
Latest Release
v0.0.0-20200625191800-a2d82c14f745
over 5 years ago
Versions
1
Dependent Packages
2
Dependent Repos
3
Links
Registry proxy.golang.org
Source Repository
Docs Documentation
JSON API View JSON
CodeMeta codemeta.json
Package Details
PURL pkg:golang/github.com/logrange/linker
spec
License Apache-2.0
Namespace github.com/logrange
First Release over 5 years ago
Last Synced 7 days ago
Repository
Stars 36 on GitHub
Forks 6 on GitHub
Rankings on proxy.golang.org
Overall Top 5.2%
Dependent packages Top 3.7%
Dependent repos Top 3.0%
Forks Top 7.7%