Closed waqasrasheed86 closed 2 years ago
You're not doing what you think you're doing. And I can't tell if your problem is not understanding container caches, or just how Resolver behaves in general.
When you do resolver.cache.reset()
, you're clearing the container cache. You're not deleting that container's registrations.
Here's an updated test script that succeeds...
func testRegistrationResetUnregistersServicesCustomResolver() {
let resolver = Resolver()
// register using the container's cache
resolver.register { XYZNameService("blackstone") }.scope(.container)
// resolve it
let service1: XYZNameService? = resolver.optional()
XCTAssertNotNil(service1)
XCTAssert(service1?.name == "blackstone")
// update registration
resolver.register { XYZNameService("houdini") }.scope(.container)
// resolving again returns cached instance
let service2: XYZNameService? = resolver.optional()
XCTAssertNotNil(service2)
XCTAssert(service2?.name == "blackstone")
// reset cached container scope
resolver.cache.reset()
// with nothing in cache resolver returns new registraion
let service3: XYZNameService? = resolver.optional()
XCTAssertNotNil(service3)
XCTAssert(service3?.name == "houdini")
}
Here is the Test Case that is failing : XCTAssertNil(service2) should nil but in case of Custom Resolver, it does not reset it.