44
55/// Protocol for adding functionality to the container
66public protocol Behavior {
7+ /// Whether the container should report resolutions to this Behavior.
8+ /// If `true`, `container(_:didResolve:name:)` will be called after each successful resolution.
9+ /// Defaults to `false`.
10+ var shouldReportResolution : Bool { get }
11+
712 /// This will be invoked on each behavior added to the `container` for each `entry` added to the container using
813 /// one of the `register()` or type forwarding methods
914 ///
@@ -21,4 +26,31 @@ public protocol Behavior {
2126 toService entry: ServiceEntry < Service > ,
2227 withName name: String ?
2328 )
29+
30+ /// This will be invoked after a successful resolution if `shouldReportResolution` is `true`.
31+ ///
32+ /// - Parameters:
33+ /// - container: container from which the service was resolved
34+ /// - serviceType: The type that was resolved
35+ /// - name: The registration name used for resolution (if any)
36+ /// - duration: The time taken to resolve the service
37+ func container< Service> (
38+ _ container: SwinjectContainer ,
39+ didResolve serviceType: Service . Type ,
40+ name: String ? ,
41+ duration: Duration
42+ )
43+ }
44+
45+ // MARK: - Default Implementations
46+
47+ public extension Behavior {
48+ var shouldReportResolution : Bool { false }
49+
50+ func container< Service> (
51+ _ container: SwinjectContainer ,
52+ didResolve serviceType: Service . Type ,
53+ name: String ? ,
54+ duration: Duration
55+ ) { }
2456}
0 commit comments