Socket
Socket
Sign inDemoInstall

github.com/insolar/component-manager

Package Overview
Dependencies
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/insolar/component-manager

This package provides dependency injection and lifecycle management for component based monolith architecture. Dependency injection feature is based on reflection. The package also provides Initer, Starter and Stopper interfaces for lifecycle management. A component is a struct which implements one or several interfaces.


Version published

Readme

Source

Overview

Component Manager provides dependency injection and lifecycle management for component-based monolith architecture apps.

See Demo application

A Component is a struct which can have dependencies and/or can implement lifecycle interfaces.

Build Status GolangCI Go Report Card GoDoc codecov

Features

  • two step initialization
  • reflect based dependency injection for interfaces
  • resolving circular dependency
  • components lifecycle support
  • ordered start, gracefully stop with reverse order
  • easy component and integration tests with mock
  • subcomponents support
  • reduce boilerplate code

Contetns

Basic usage

Object definition

A Component is a struct which can have dependencies and/or can implement lifecycle interfaces.

Dependencies defined as fields in the struct and must be an interface type. have to be exportable because reflect can set only exportable struct fields. Also Dependencies must have tag inject:"".

type Supermarket struct {
	Warehouse core.Warehouse `inject:""`
}
	cm := component.NewManager(nil)
	cm.Register(producer.NewFarm(), producer.NewDoorFactory())
	cm.Register(&supermarket.Supermarket{}, &warehouse.Warehouse{})
	cm.Register(NewCustomer("Bob"), NewCustomer("Alice"))
	cm.Inject()

Component lifecycle

Usually components lives from app process executes till process finished.

  • new(instance created, first initialization)
  • inject(required dependency injected)
  • init(second initialization)
  • start(component can call their dependency interfaces, run goroutines)
  • prepare stop(optional)
  • stop (gracefully stop goroutines, close descriptors)

Component constructor

Constructor with config as param.

Init and start

When should use Init and when Start? What does it means.

Stop and gracefully stop

tbd

intefaces

type Initer interface {
	Init(ctx context.Context) error
}

type Starter interface {
	Start(ctx context.Context) error
}

type Stopper interface {
	Stop(ctx context.Context) error
}

Similar projects

FAQs

Last updated on 11 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc