@@ -56,16 +56,46 @@ final class FactoryScopeTests: XCTestCase {
5656 XCTAssertTrue ( service2? . id != service3? . id)
5757 }
5858
59+ func testExplicitProtocolSharedScope( ) throws {
60+ var service1 : MyServiceType ? = Container . sharedExplicitProtocol ( )
61+ var service2 : MyServiceType ? = Container . sharedExplicitProtocol ( )
62+ XCTAssertNotNil ( service1)
63+ XCTAssertNotNil ( service2)
64+ // Shared cached item ids should match
65+ XCTAssertTrue ( service1? . id == service2? . id)
66+ service1 = nil
67+ service2 = nil
68+ let service3 : MyServiceType ? = Container . sharedExplicitProtocol ( )
69+ XCTAssertNotNil ( service3)
70+ // Shared instance should have released so new and old ids should not match
71+ XCTAssertTrue ( service2? . id != service3? . id)
72+ }
73+
74+ func testInferredProtocolSharedScope( ) throws {
75+ var service1 : MyServiceType ? = Container . sharedInferredProtocol ( )
76+ var service2 : MyServiceType ? = Container . sharedInferredProtocol ( )
77+ XCTAssertNotNil ( service1)
78+ XCTAssertNotNil ( service2)
79+ // Shared cached item ids should match
80+ XCTAssertTrue ( service1? . id == service2? . id)
81+ service1 = nil
82+ service2 = nil
83+ let service3 : MyServiceType ? = Container . sharedInferredProtocol ( )
84+ XCTAssertNotNil ( service3)
85+ // Shared instance should have released so new and old ids should not match
86+ XCTAssertTrue ( service2? . id != service3? . id)
87+ }
88+
5989 func testOptionalSharedScope( ) throws {
60- var service1 : MyServiceType ? = Container . optionalSharedService ( )
61- var service2 : MyServiceType ? = Container . optionalSharedService ( )
90+ var service1 : MyServiceType ? = Container . sharedOptionalProtocol ( )
91+ var service2 : MyServiceType ? = Container . sharedOptionalProtocol ( )
6292 XCTAssertNotNil ( service1)
6393 XCTAssertNotNil ( service2)
6494 // Shared cached item ids should match
6595 XCTAssertTrue ( service1? . id == service2? . id)
6696 service1 = nil
6797 service2 = nil
68- let service3 : MyServiceType ? = Container . optionalSharedService ( )
98+ let service3 : MyServiceType ? = Container . sharedOptionalProtocol ( )
6999 XCTAssertNotNil ( service3)
70100 // Shared instance should have released so new and old ids should not match
71101 XCTAssertTrue ( service2? . id != service3? . id)
0 commit comments