Skip to content

Commit e029f3e

Browse files
committed
refactor(dependencies): migrate to vessel and update dependencies
- Replaced the `di` package with `vessel` for dependency injection across the application, enhancing modularity and maintainability. - Updated various dependencies, including `BurntSushi/toml` from v1.5.0 to v1.6.0, and improved Kubernetes-related libraries to their latest versions for better functionality and security. - Adjusted tests and middleware to utilize the new `vessel` context, ensuring consistency in dependency management and improving overall code clarity. - Removed outdated references and ensured all modules are aligned with the latest dependency standards.
1 parent e151c50 commit e029f3e

35 files changed

Lines changed: 856 additions & 1750 deletions

app_impl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"syscall"
1313
"time"
1414

15+
configM "github.com/xraph/confy"
1516
"github.com/xraph/forge/errors"
16-
configM "github.com/xraph/forge/internal/config"
17-
"github.com/xraph/forge/internal/di"
1817
healthinternal "github.com/xraph/forge/internal/health"
1918
"github.com/xraph/forge/internal/logger"
2019
metricsinternal "github.com/xraph/forge/internal/metrics"
2120
"github.com/xraph/forge/internal/shared"
21+
"github.com/xraph/vessel"
2222
)
2323

2424
// app implements the App interface.
@@ -837,8 +837,8 @@ func (a *app) handleInfo(ctx Context) error {
837837

838838
// buildExtensionGraph builds a dependency graph from registered extensions.
839839
// Returns the graph, extension map for lookup, and the topologically sorted order.
840-
func (a *app) buildExtensionGraph() (*di.DependencyGraph, map[string]Extension, []string, error) {
841-
graph := di.NewDependencyGraph()
840+
func (a *app) buildExtensionGraph() (*vessel.DependencyGraph, map[string]Extension, []string, error) {
841+
graph := vessel.NewDependencyGraph()
842842
extMap := make(map[string]Extension)
843843

844844
for _, ext := range a.extensions {

di.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package forge
22

33
import (
4-
"github.com/xraph/forge/internal/di"
5-
"github.com/xraph/forge/internal/shared"
4+
"github.com/xraph/vessel"
65
)
76

87
// Container provides dependency injection with lifecycle management.
9-
type Container = shared.Container
8+
type Container = vessel.Vessel
109

1110
// Scope represents a lifetime scope for scoped services
1211
// Typically used for HTTP requests or other bounded operations.
13-
type Scope = shared.Scope
12+
type Scope = vessel.Scope
1413

1514
// Factory creates a service instance.
16-
type Factory = shared.Factory
15+
type Factory = vessel.Factory
1716

1817
// ServiceInfo contains diagnostic information.
19-
type ServiceInfo = shared.ServiceInfo
18+
type ServiceInfo = vessel.ServiceInfo
2019

2120
// NewContainer creates a new DI container.
2221
func NewContainer() Container {
23-
return di.NewContainer()
22+
return vessel.New()
2423
}

di_helpers.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package forge
33
import (
44
"context"
55

6-
"github.com/xraph/forge/internal/di"
76
"github.com/xraph/forge/internal/shared"
7+
"github.com/xraph/vessel"
88
)
99

1010
// Resolve with type safety.
1111
func Resolve[T any](c Container, name string) (T, error) {
12-
return di.Resolve[T](c, name)
12+
return vessel.Resolve[T](c, name)
1313
}
1414

1515
// Must resolves or panics - use only during startup.
1616
func Must[T any](c Container, name string) T {
17-
return di.Must[T](c, name)
17+
return vessel.Must[T](c, name)
1818
}
1919

2020
// ResolveReady resolves a service with type safety, ensuring it and its dependencies are started first.
@@ -34,28 +34,28 @@ func Must[T any](c Container, name string) T {
3434
// return nil
3535
// }
3636
func ResolveReady[T any](ctx context.Context, c Container, name string) (T, error) {
37-
return di.ResolveReady[T](ctx, c, name)
37+
return vessel.ResolveReady[T](ctx, c, name)
3838
}
3939

4040
// MustResolveReady resolves or panics, ensuring the service is started first.
4141
// Use only during startup/registration phase.
4242
func MustResolveReady[T any](ctx context.Context, c Container, name string) T {
43-
return di.MustResolveReady[T](ctx, c, name)
43+
return vessel.MustResolveReady[T](ctx, c, name)
4444
}
4545

4646
// RegisterSingleton is a convenience wrapper for singleton services.
4747
func RegisterSingleton[T any](c Container, name string, factory func(Container) (T, error)) error {
48-
return di.RegisterSingleton[T](c, name, factory)
48+
return vessel.RegisterSingleton[T](c, name, factory)
4949
}
5050

5151
// RegisterTransient is a convenience wrapper for transient services.
5252
func RegisterTransient[T any](c Container, name string, factory func(Container) (T, error)) error {
53-
return di.RegisterTransient[T](c, name, factory)
53+
return vessel.RegisterTransient[T](c, name, factory)
5454
}
5555

5656
// RegisterScoped is a convenience wrapper for request-scoped services.
5757
func RegisterScoped[T any](c Container, name string, factory func(Container) (T, error)) error {
58-
return di.RegisterScoped[T](c, name, factory)
58+
return vessel.RegisterScoped[T](c, name, factory)
5959
}
6060

6161
// RegisterSingletonWith registers a singleton service with typed dependency injection.
@@ -70,7 +70,7 @@ func RegisterScoped[T any](c Container, name string, factory func(Container) (T,
7070
// },
7171
// )
7272
func RegisterSingletonWith[T any](c Container, name string, args ...any) error {
73-
return di.RegisterSingletonWith[T](c, name, args...)
73+
return vessel.RegisterSingletonWith[T](c, name, args...)
7474
}
7575

7676
// RegisterTransientWith registers a transient service with typed dependency injection.
@@ -85,7 +85,7 @@ func RegisterSingletonWith[T any](c Container, name string, args ...any) error {
8585
// },
8686
// )
8787
func RegisterTransientWith[T any](c Container, name string, args ...any) error {
88-
return di.RegisterTransientWith[T](c, name, args...)
88+
return vessel.RegisterTransientWith[T](c, name, args...)
8989
}
9090

9191
// RegisterScopedWith registers a scoped service with typed dependency injection.
@@ -100,61 +100,61 @@ func RegisterTransientWith[T any](c Container, name string, args ...any) error {
100100
// },
101101
// )
102102
func RegisterScopedWith[T any](c Container, name string, args ...any) error {
103-
return di.RegisterScopedWith[T](c, name, args...)
103+
return vessel.RegisterScopedWith[T](c, name, args...)
104104
}
105105

106106
// RegisterInterface registers an implementation as an interface
107107
// Supports all lifecycle options (Singleton, Scoped, Transient).
108108
func RegisterInterface[I, T any](c Container, name string, factory func(Container) (T, error), opts ...RegisterOption) error {
109-
return di.RegisterInterface[I, T](c, name, factory, opts...)
109+
return vessel.RegisterInterface[I, T](c, name, factory, opts...)
110110
}
111111

112112
// RegisterValue registers a pre-built instance (always singleton).
113113
func RegisterValue[T any](c Container, name string, instance T) error {
114-
return di.RegisterValue[T](c, name, instance)
114+
return vessel.RegisterValue[T](c, name, instance)
115115
}
116116

117117
// RegisterSingletonInterface is a convenience wrapper.
118118
func RegisterSingletonInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error {
119-
return di.RegisterSingletonInterface[I, T](c, name, factory)
119+
return vessel.RegisterSingletonInterface[I, T](c, name, factory)
120120
}
121121

122122
// RegisterScopedInterface is a convenience wrapper.
123123
func RegisterScopedInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error {
124-
return di.RegisterScopedInterface[I, T](c, name, factory)
124+
return vessel.RegisterScopedInterface[I, T](c, name, factory)
125125
}
126126

127127
// RegisterTransientInterface is a convenience wrapper.
128128
func RegisterTransientInterface[I, T any](c Container, name string, factory func(Container) (T, error)) error {
129-
return di.RegisterTransientInterface[I, T](c, name, factory)
129+
return vessel.RegisterTransientInterface[I, T](c, name, factory)
130130
}
131131

132132
// ResolveScope is a helper for resolving from a scope.
133133
func ResolveScope[T any](s Scope, name string) (T, error) {
134-
return di.ResolveScope[T](s, name)
134+
return vessel.ResolveScope[T](s, name)
135135
}
136136

137137
// MustScope resolves from scope or panics.
138138
func MustScope[T any](s Scope, name string) T {
139-
return di.MustScope[T](s, name)
139+
return vessel.MustScope[T](s, name)
140140
}
141141

142142
// GetLogger resolves the logger from the container
143143
// Returns the logger instance and an error if resolution fails.
144144
func GetLogger(c Container) (Logger, error) {
145-
return di.GetLogger(c)
145+
return vessel.GetLogger(c)
146146
}
147147

148148
// GetMetrics resolves the metrics from the container
149149
// Returns the metrics instance and an error if resolution fails.
150150
func GetMetrics(c Container) (Metrics, error) {
151-
return di.GetMetrics(c)
151+
return vessel.GetMetrics(c)
152152
}
153153

154154
// GetHealthManager resolves the health manager from the container
155155
// Returns the health manager instance and an error if resolution fails.
156156
func GetHealthManager(c Container) (HealthManager, error) {
157-
return di.GetHealthManager(c)
157+
return vessel.GetHealthManager(c)
158158
}
159159

160160
// =============================================================================
@@ -211,45 +211,45 @@ func DepLazyOptionalSpec(name string) Dep {
211211
// LazyRef wraps a dependency that is resolved on first access.
212212
// This is useful for breaking circular dependencies or deferring
213213
// resolution of expensive services until they're actually needed.
214-
type LazyRef[T any] = di.Lazy[T]
214+
type LazyRef[T any] = vessel.LazyRef[T]
215215

216216
// OptionalLazyRef wraps an optional dependency that is resolved on first access.
217217
// Returns nil without error if the dependency is not found.
218-
type OptionalLazyRef[T any] = di.OptionalLazy[T]
218+
type OptionalLazyRef[T any] = vessel.OptionalLazy[T]
219219

220220
// ProviderRef wraps a dependency that creates new instances on each access.
221221
// This is useful for transient dependencies where a fresh instance is needed each time.
222-
type ProviderRef[T any] = di.Provider[T]
222+
type ProviderRef[T any] = vessel.Provider[T]
223223

224224
// LazyAny is a non-generic lazy wrapper used with LazyInject.
225225
// Use this type in your factory function when using LazyInject[T].
226-
type LazyAny = di.LazyAny
226+
type LazyAny = vessel.LazyAny
227227

228228
// OptionalLazyAny is a non-generic optional lazy wrapper used with LazyOptionalInject.
229229
// Use this type in your factory function when using LazyOptionalInject[T].
230-
type OptionalLazyAny = di.OptionalLazyAny
230+
type OptionalLazyAny = vessel.OptionalLazyAny
231231

232232
// NewLazyRef creates a new lazy dependency wrapper.
233233
func NewLazyRef[T any](c Container, name string) *LazyRef[T] {
234-
return di.NewLazy[T](c, name)
234+
return vessel.NewLazy[T](c, name)
235235
}
236236

237237
// NewOptionalLazyRef creates a new optional lazy dependency wrapper.
238238
func NewOptionalLazyRef[T any](c Container, name string) *OptionalLazyRef[T] {
239-
return di.NewOptionalLazy[T](c, name)
239+
return vessel.NewOptionalLazy[T](c, name)
240240
}
241241

242242
// NewProviderRef creates a new provider for transient dependencies.
243243
func NewProviderRef[T any](c Container, name string) *ProviderRef[T] {
244-
return di.NewProvider[T](c, name)
244+
return vessel.NewProvider[T](c, name)
245245
}
246246

247247
// =============================================================================
248248
// Typed Injection Helpers
249249
// =============================================================================
250250

251251
// InjectOption represents a dependency injection option with type information.
252-
type InjectOption = di.InjectOption
252+
type InjectOption = vessel.InjectOption
253253

254254
// Inject creates an eager injection option for a dependency.
255255
// The dependency is resolved immediately when the service is created.
@@ -261,30 +261,30 @@ type InjectOption = di.InjectOption
261261
// func(db *bun.DB) (*UserService, error) { ... },
262262
// )
263263
func Inject[T any](name string) InjectOption {
264-
return di.Inject[T](name)
264+
return vessel.Inject[T](name)
265265
}
266266

267267
// LazyInject creates a lazy injection option for a dependency.
268268
// The dependency is resolved on first access via Lazy[T].Get().
269269
func LazyInject[T any](name string) InjectOption {
270-
return di.LazyInject[T](name)
270+
return vessel.LazyInject[T](name)
271271
}
272272

273273
// OptionalInject creates an optional injection option for a dependency.
274274
// The dependency is resolved immediately but returns nil if not found.
275275
func OptionalInject[T any](name string) InjectOption {
276-
return di.OptionalInject[T](name)
276+
return vessel.OptionalInject[T](name)
277277
}
278278

279279
// LazyOptionalInject creates a lazy optional injection option.
280280
// The dependency is resolved on first access and returns nil if not found.
281281
func LazyOptionalInject[T any](name string) InjectOption {
282-
return di.LazyOptionalInject[T](name)
282+
return vessel.LazyOptionalInject[T](name)
283283
}
284284

285285
// ProviderInject creates an injection option for a transient dependency provider.
286286
func ProviderInject[T any](name string) InjectOption {
287-
return di.ProviderInject[T](name)
287+
return vessel.ProviderInject[T](name)
288288
}
289289

290290
// Provide registers a service with typed dependency injection.
@@ -304,10 +304,10 @@ func ProviderInject[T any](name string) InjectOption {
304304
// },
305305
// )
306306
func Provide[T any](c Container, name string, args ...any) error {
307-
return di.Provide[T](c, name, args...)
307+
return vessel.Provide[T](c, name, args...)
308308
}
309309

310310
// ProvideWithOpts is like Provide but accepts additional RegisterOptions.
311311
func ProvideWithOpts[T any](c Container, name string, opts []RegisterOption, args ...any) error {
312-
return di.ProvideWithOpts[T](c, name, opts, args...)
312+
return vessel.ProvideWithOpts[T](c, name, opts, args...)
313313
}

extensions/auth/providers/ldap_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"github.com/stretchr/testify/require"
1515
"github.com/xraph/forge"
1616
"github.com/xraph/forge/extensions/auth"
17-
forge_http "github.com/xraph/forge/internal/http"
18-
"github.com/xraph/forge/internal/logger"
17+
forge_http "github.com/xraph/go-utils/http"
18+
logger "github.com/xraph/go-utils/log"
1919
)
2020

2121
func newMockLogger() forge.Logger {
22-
return logger.NewTestLogger()
22+
return logger.NewNoopLogger()
2323
}
2424

2525
func TestDefaultLDAPConfig(t *testing.T) {

0 commit comments

Comments
 (0)