MCPcopy Index your code
hub / github.com/dimes/dihedral

github.com/dimes/dihedral @0.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.8 ↗ · + Follow
91 symbols 229 edges 22 files 58 documented · 64%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Dihedral

Build Status

Dihedral is a compile-time injection framework for Go.

Getting started

> go get -u github.com/dimes/dihedral

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("http://hello.world")
}

Create a component as the root of the dependency injection:

type ServiceComponent interface {
    InjectService() *Service
}

Create a definition with the target component and the module configuration:

type ServiceDefinition interface {
    Modules() (*ServiceModule, dbstore.DBBindingModule)
    Target() ServiceComponent
}

Generate the bindings

> dihedral -definition ServiceDefinition

Use the bindings

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

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 that have a different scope than the parent component.

Extension points exported contracts — how you extend this code

Assignment (Interface)
Assignment represents a way of getting a injected value, either by a provider or by an injectable factory method [2 implementers]
gen/assignment.go
ResolvedType (Interface)
ResolvedType is an interface that represents a type provided by an injection source. Currently, the only injection sourc [1 …
resolver/resolver.go
ServiceComponent (Interface)
ServiceComponent defines the top level component. The return type of the `Modules()` method is used as a list of modules [1 …
internal/example/bindings/bindings.go
DBStore (Interface)
DBStore is an interface for Database interaction [1 implementers]
internal/example/dbstore/dbstore.go
BindingModule (Interface)
BindingModule binds SpecificBoundType to BoundType
internal/example/bindings/bindings.go
ServiceDefinition (Interface)
ServiceDefinition defines the target and the modules to include
internal/example/bindings/bindings.go
DBBindingModule (Interface)
DBBindingModule binds the MemoryDBStore to the DBStore interface for injection
internal/example/dbstore/bindings.go

Core symbols most depended-on inside this repo

IDFromNamed
called by 12
typeutil/typeutil.go
SanitizeName
called by 8
gen/util.go
CastTo
called by 5
gen/assignment.go
GetSourceAssignment
called by 3
gen/assignment.go
AssignmentForFieldType
called by 3
gen/assignment.go
newInjectionTarget
called by 3
gen/gen.go
HasFieldOfType
called by 3
typeutil/typeutil.go
getNodesFromInterface
called by 2
resolver/resolver.go

Shape

Method 35
Function 24
Struct 20
Interface 7
TypeAlias 5

Languages

Go100%

Modules by API surface

internal/example/bindings/bindings.go14 symbols
gen/assignment.go14 symbols
resolver/resolver.go11 symbols
internal/example/dbstore/dbstore.go7 symbols
internal/example/dbstore/bindings.go7 symbols
gen/gen.go6 symbols
internal/example/bindings/digen/component.go5 symbols
typeutil/typeutil.go4 symbols
internal/example/example.go4 symbols
gen/provider.go3 symbols
gen/factory.go3 symbols
structs/structs.go2 symbols

For agents

$ claude mcp add dihedral \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact