Skip to main content

Clone

Clone has the same service registrations as its parent, but it doesn't share the invoked service state.

Cloning a container can be very useful for test purposes.

injector := do.New()

Provide[*Car](i, NewCar)
Provide[*Engine](i, NewEngine)

// reset scope
injector = injector.Clone()

Clone with options

injector := do.New()

Provide[*Car](i, NewCar)
Provide[Engine](i, NewEngine)

// clone
injector = injector.Clone()

// replace Engine by *MockEngine
do.Override[Engine](injector, func (i do.Injector) (Engine, error) {
return &MockEngine{}, nil
})