Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ run:
tests: false
allow-parallel-runners: true
linters:
exclusions:
paths:
- samples

default: none
enable:
- bodyclose
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ func (c *Container) Resolve(target interface{}) error
func (c *Container) MustResolve(target interface{})
```

## ⚠️ Current Limitations

- **Exact Type Matching Only** - No interface binding support
- **Basic Named Dependencies** - No tags or name-based resolution
- **No Lifecycle Hooks** - Basic startup/shutdown only
- **Limited ctor return types** - Only support ctors which returns pointers
- **Only types in ctor return** - Doesn't support interfaces as ctor return value
- **Only one return value** - one ctor = one value

## 🛣️ Roadmap

- [x] Basic dependency resolution with reflection
Expand All @@ -104,6 +95,15 @@ func (c *Container) MustResolve(target interface{})
- [x] Error handling
- [ ] Named dependency resolution
- [x] Dependency graph visualization
- [x] Error handling
- [ ] Scope support
- [ ] Lifecycle support

## ⚠️ Current Limitations
- **Basic Named Dependencies** - No tags or name-based resolution
- **No Lifecycle Hooks** - Basic startup/shutdown only
- **Limited ctor return types** - Only support ctors which returns pointers (*T) or (*T, error)
- **Only types in ctor return** - Doesn't support interfaces as ctor return value

## 📊 Benefits

Expand Down
9 changes: 8 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// container.go
package compoapp

import (
Expand All @@ -25,6 +24,8 @@ type Container struct {
typesCtors map[reflect.Type]*constructorInfo

debug bool
// mark if container resolved
resolved bool
}

// Debug enables debug mode
Expand Down Expand Up @@ -211,6 +212,8 @@ func (c *Container) Resolve(target any) error {
instanceValue := reflect.ValueOf(instance)
if instanceValue.Type().AssignableTo(targetType) {
targetValue.Elem().Set(instanceValue)

c.resolved = true
return nil
}
return fmt.Errorf("resolved instance type %s is not assignable to target type %s",
Expand Down Expand Up @@ -455,6 +458,10 @@ const dotHeader string = `digraph DependencyGraph {
func (c *Container) Visualize(filepath string) error {
c.mu.RLock()
defer c.mu.RUnlock()

if !c.resolved {
return fmt.Errorf("you must call MustResolve or Resolve first")
}
//nolint:gosec
f, err := os.Create(filepath)
if err != nil {
Expand Down
Loading
Loading