Closed minuscorp closed 2 years ago
Bump? @hmlongco
I feel that if we needed Hashable and Equatable we should just add it rather than force everyone to roll their own.
That said... I don't get the "concrete need" you're attempting to solve. Why would you want to create collections of named dependencies for registration in the first place?
We have different configurations that register different services and we test with collections which name to register with which namespace. So we use names as keys and values as services, collections of services and such.
Resolver.Name now conforms to Hashable and Equatable.
func testResolverNameHashableConformance() {
let registrations: [Resolver.Name:XYZNameService] = [
.fred : XYZNameService("Fred"),
.barney : XYZNameService("Barney"),
]
registrations.forEach { (name, service) in
resolver.register(name: name) { service }
}
let fred: XYZNameService? = resolver.optional(name: .fred)
let barney: XYZNameService? = resolver.optional(name: .barney)
// Check all services resolved
XCTAssertNotNil(fred)
XCTAssertNotNil(barney)
// Check correct service factories called
XCTAssert(fred?.name == "Fred")
XCTAssert(barney?.name == "Barney")
}
Right now, there's no way to build objects like
[Resolver.Name: SomeObject]
in order to register collections of named dependencies becauseResolver.Name
does not conform toHashable
. As it is a very concrete need, instead of adding the conformance inside the library I see more convenient to just makepublic
therawValue
so it is possible to debug names and make external new conformances.