@@ -2,24 +2,24 @@ import Foundation
22
33public class Container {
44 @MainActor
5- private ( set ) static var root = Container ( )
5+ static var root = Container ( )
66
77 /// Stored object instance factories.
8- var modules : [ String : Module ] = [ : ]
8+ var _storage : [ String : Module ] = [ : ]
99
1010 public init ( ) { }
11- deinit { modules . removeAll ( ) }
11+ deinit { _storage . removeAll ( ) }
1212}
1313
1414public extension Container {
1515 /// Registers a specific type and its instantiating factory.
1616 @discardableResult
1717 func register( module: Module ) -> Self {
1818 let key = module. name
19- if let _ = modules [ key] {
19+ if let _ = _storage [ key] {
2020 assertionFailure ( " \( key) Key is existed. Please check module \( module) " )
2121 }
22- modules [ key] = module
22+ _storage [ key] = module
2323 return self
2424 }
2525
@@ -49,15 +49,15 @@ extension Container {
4949 static func weakResolve< T, U: InjectionKeyType > ( for type: U . Type ) -> T ? {
5050 root. module ( type) ? . resolve ( ) as? T
5151 }
52-
52+
5353 /// Check if the dependency is registered in the container.
5454 static func isRegistered< T: InjectionKeyType > ( _ type: T . Type ) -> Bool {
5555 root. module ( type) != nil
5656 }
5757
5858 func module< T: InjectionKeyType > ( _ type: T . Type ) -> Module ? {
5959 let keyName = KeyName ( type) . name
60- return modules [ keyName]
60+ return _storage [ keyName]
6161 }
6262}
6363
@@ -95,14 +95,16 @@ public extension Container {
9595 // Used later in property wrapper
9696 Self . root = self
9797 }
98- }
9998
100- #if DEBUG
101- @MainActor
102- public extension Container {
103- static func clear( ) {
104- root = . init( )
99+ static subscript< T: InjectionKeyType > ( _ type: T . Type ) -> T . Value {
100+ resolve ( for: type)
105101 }
106- }
107102
108- #endif
103+ var count : Int {
104+ _storage. count
105+ }
106+
107+ var isEmpty : Bool {
108+ _storage. isEmpty
109+ }
110+ }
0 commit comments