hmlongco / Factory

A new approach to Container-Based Dependency Injection for Swift and SwiftUI.
MIT License
1.7k stars 107 forks source link

Is there a way to reset all containers in tests #204

Closed tahirmt closed 2 months ago

tahirmt commented 2 months ago

Hi I have defined a number of custom containers and in my tests I want to call .reset() on all of them instead of remembering to add a line to reset every new container I end up creating later.

Is there a way to do this now?

hmlongco commented 2 months ago

No, but...

let containers: [ManagedContainer] = [c1, c2, c3, c6, c5, c4]
containers.forEach { $0.reset() }
tahirmt commented 2 months ago

Yeah that's kind of what I have now. It's just having to update this every time a new container is introduced.

hmlongco commented 2 months ago

Make each container autoRegistering and register with a global set/array.