workfx

package module
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

workfx

Modules enabling your Fx application to effectively track and commit changes to your entities.

GoDoc Build Status Coverage Status Release License Blog

What is it?

workfx empowers your Fx application with the ability to track and commit atomic changes to your entities. It essentially defines a core set of Fx modules that can be imported into your Fx application so that it can leverage work.Uniter instances.

Why use it?

With workfx, you can seamlessly integrate work units into your Fx application. On top of the various benefits of using work units in general, the workfx module provides:

  • a well defined set of modules that can be used in isolation or in conjuction.
  • integrations with Fx dependency management, reducing the necessary code to create work.Uniter instances in your Fx application.

Example Usage

Provide the Module
package main

import (
	"github.com/freerware/workfx"
	"go.uber.org/fx"
)

func main() {
	fx.New(
		... // modules for your Fx application.
		workfx.Modules.SQLUnit,
	).Run()
}
Named Values

To support Fx applications that may leverage more than one work unit type, workfx utilizes named values. This means that in order to inject work.Uniter instances, you must add the name Go tag. In addition, it's common for applications leveraging SQL databases to support configurations with multiple database instances, such as primary (read-write) and replicas (read-only). In order to accommodate these applications, the name tag is used as well.

Name Type Description
sqlWorkUniter work.Uniter SQL Uniter
bestEffortWorkUniter work.Uniter Best Effort Uniter
rwDB *sql.DB Read-Write DB
type Parameters struct {
	fx.In

	uniter work.Uniter `name:"sqlWorkUniter"`
}
Value Groups

In addition to named values, workfx also makes use of value groups as a convenience for injecting multiple instances of the same type.

Name Type Description
workUniter work.Uniter Work Uniter Group
type Parameters struct {
	fx.In

	uniters []work.Uniter `group:"workUniter"`
}

Contribute

Want to lend us a hand? Check out our guidelines for contributing.

License

We are rocking an Apache 2.0 license for this project.

Code of Conduct

Please check out our code of conduct to get up to speed how we do things.

Artwork

Discovered via the interwebs, the artwork was created by Marcus Olsson and Jon Calhoun for Gophercises.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Modules = struct {
	SQLUnit        fx.Option
	BestEffortUnit fx.Option
}{
	SQLUnit: fx.Options(
		fx.Provide(func(p SQLUnitParameters) SQLWorkUniterResult {
			options := []work.Option{}
			if p.Logger != nil {
				options = append(options, work.UnitLogger(p.Logger))
			}
			if p.Scope != nil {
				options = append(options, work.UnitScope(p.Scope))
			}
			return SQLWorkUniterResult{
				WorkUniter: work.NewSQLUniter(p.Mappers, p.DB, options...),
			}
		})),

	BestEffortUnit: fx.Options(
		fx.Provide(func(p UnitParameters) BestEffortWorkUniterResult {
			options := []work.Option{}
			if p.Logger != nil {
				options = append(options, work.UnitLogger(p.Logger))
			}
			if p.Scope != nil {
				options = append(options, work.UnitScope(p.Scope))
			}
			return BestEffortWorkUniterResult{
				WorkUniter: work.NewBestEffortUniter(p.Mappers, options...),
			}
		})),
}

Modules defines the various work unit Fx modules.

Functions

This section is empty.

Types

type BestEffortWorkUniterResult

type BestEffortWorkUniterResult struct {
	fx.Out

	WorkUniter work.Uniter `name:"bestEffortWorkUniter",group:"workUniter"`
}

BestEffortWorkUniterResult defines the best effort uniter to be provided to the dependency injection container.

type SQLUnitParameters

type SQLUnitParameters struct {
	fx.In

	Mappers map[work.TypeName]work.SQLDataMapper
	DB      *sql.DB     `name:"rwDB"`
	Logger  *zap.Logger `optional:"true"`
	Scope   tally.Scope `optional:"true"`
}

SQLUnitParameters encapsulates the various dependencies required to construct SQL work units.

type SQLWorkUniterResult

type SQLWorkUniterResult struct {
	fx.Out

	WorkUniter work.Uniter `name:"sqlWorkUniter",group:"workUniter"`
}

SQLWorkUniterResult defines the SQL work uniter to be provided to the dependency injection container.

type UnitParameters

type UnitParameters struct {
	fx.In

	Mappers map[work.TypeName]work.DataMapper
	Logger  *zap.Logger `optional:"true"`
	Scope   tally.Scope `optional:"true"`
}

UnitParameters encapsulates the various dependencies required to contruct various work units, such as the best effort work unit.

Jump to

Keyboard shortcuts

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