Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DigExt

A quick and dirty library that adds things that I've felt in the past are missing from Uber's dig dependency library.

Interfaces

One big thing dig is missing is an interface that's the same for Scope and Container - this makes it harder to use interchangeably, so this package uses an interface for the Container type instead of just a struct.

Error returns

While Go's error returns are amazing, it does get a bit cumbersome to handle errors when you're registering many constructors and invoking them.

This package provides a Must* for the usual functions, making it simpler to register items if you don't mind throwing fatal errors when things don't work (which, when you use the dig library as intended for startup resolution works well)

d.MustProvide(func() *http.Client {
	return &http.Client{}
})

d.MustInvoke(func(c *http.Client) {
	c.Do(...)
})

Multi-function

When you're registering a lot of constructors, it gets tedious to call container.Provide(...) a lot, check all errors, and then continue on.

This package includes functions to do multiple operations, like Provides(...), Invokes(...), etc, at the cost of the Options.

d.Provides(
	func() *http.Client {
		return &http.Client{}
    }, 
	func() digext.Container {
		return d
    },
)

About

An extension to Uber's dig library that adds a base interface and nice-to-have functionality

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages