Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit c0d0cb5 Apr 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Checking in Apr 8, 2019
docs Use left instead of width in docs Apr 20, 2019
embeds Provided modules Apr 9, 2019
gen Format generated code and add generated code tag Apr 22, 2019
internal/example Fix godoc Apr 23, 2019
resolver Make resolved type an interface in preparation for subcomponents Apr 20, 2019
something Checking in Apr 8, 2019
structs Checking in Apr 8, 2019
typeutil di -> dihedral Apr 10, 2019
.travis.yml Re-add generated code Apr 22, 2019
LICENSE Create LICENSE Apr 10, 2019 Update Apr 22, 2019
dihedral.go Format generated code and add generated code tag Apr 22, 2019
dihedral_test.go Add test Apr 22, 2019
go.mod Add test Apr 22, 2019
go.sum Add test Apr 22, 2019


Build Status

Dihedral is a compile-time injection framework for Go.

Getting started

> go get -u

Create a type you want injected

type ServiceEndpoint string  // Name this string "ServiceEndpoint"
type Service struct {
    inject  embeds.Inject    // Auto-inject this struct 
    Endpoint ServiceEndpoint // Inject a string with name "ServiceEndpoint"

Create a module to provide non-injected dependencies

// Each public method on this struct provides a type
type ServiceModule struct {}
func (s *ServiceModule) ProvidesServiceEndpoint() ServiceEndpoint {
    return ServiceEndpoint("")

Create a component as the root of the dependency injection

interface ServiceComponent {
    Modules() *MyModule      // Tells dihedral which modules to include
    InjectService() *Service // Tells dihedral the root of the DI graph

Generate the bindings

> dihedral -component ServiceComponent

Use the bindings

func main() {
    // dihedral generates the digen package
    component := digen.ServiceComponent()
    service := component.InjectService()
    fmt.Println(string(injected.Endpoint)) # Prints ""

Further Reading

Differences from Wire

Wire, Google's injection framework, is another compile time framework for Go. Both frameworks are inspired by Dagger. Dihedral differs from Wire in that Dihedral focuses on auto-injected components and self-contained modules, whereas Wire focuses more on type registration via provider functions. Dihedral also leverages struct receivers for better organization of runtime provided types. These features make Dihedral nicer to work with.

Dihedral's component structure also enables one to have multiple injected components that share modules. The type annotation system allows for auto-injected components, provided modules, and, in the future, sub-components and have a different scope than the parent component.

You can’t perform that action at this time.