From 2ac8692bca3ee3d8a44027830d48a99a87e13ea4 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Mon, 7 May 2018 17:28:56 -0700 Subject: [PATCH] Remove module name from component path Since we currently do not support module name for collision resolution, we should just remove it from the path. --- Foundation/Sources/NeedleFoundation/Component.swift | 5 ++++- Foundation/Tests/NeedleFoundationTests/ComponentTests.swift | 2 +- .../DependencyProviderRegistryTests.swift | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Foundation/Sources/NeedleFoundation/Component.swift b/Foundation/Sources/NeedleFoundation/Component.swift index e94e5a47..2650853d 100644 --- a/Foundation/Sources/NeedleFoundation/Component.swift +++ b/Foundation/Sources/NeedleFoundation/Component.swift @@ -47,7 +47,10 @@ open class Component: ComponentType { // Use `lazy var` to avoid computing the path repeatedly. Internally, this is always // accessed with the `__DependencyProviderRegistry`'s lock acquired. public lazy var path: String = { - return parent.path + "->\(self)" + let fullyQualifiedSelfName = String(describing: self) + let parts = fullyQualifiedSelfName.components(separatedBy: ".") + let name = parts.last ?? fullyQualifiedSelfName + return parent.path + "->\(name)" }() /// The dependency of this component. diff --git a/Foundation/Tests/NeedleFoundationTests/ComponentTests.swift b/Foundation/Tests/NeedleFoundationTests/ComponentTests.swift index c4179bb9..0e104400 100644 --- a/Foundation/Tests/NeedleFoundationTests/ComponentTests.swift +++ b/Foundation/Tests/NeedleFoundationTests/ComponentTests.swift @@ -26,7 +26,7 @@ class ComponentTests: XCTestCase { override func setUp() { super.setUp() - let path = "^->NeedleFoundationTests.TestComponent" + let path = "^->TestComponent" __DependencyProviderRegistry.instance.registerDependencyProviderFactory(for: path) {_ in return EmptyDependencyProvider() } diff --git a/Foundation/Tests/NeedleFoundationTests/DependencyProviderRegistryTests.swift b/Foundation/Tests/NeedleFoundationTests/DependencyProviderRegistryTests.swift index 87e13293..cf10e345 100644 --- a/Foundation/Tests/NeedleFoundationTests/DependencyProviderRegistryTests.swift +++ b/Foundation/Tests/NeedleFoundationTests/DependencyProviderRegistryTests.swift @@ -26,7 +26,7 @@ class DependencyProviderRegistryTests: XCTestCase { override func setUp() { super.setUp() - let path = "^->NeedleFoundationTests.MockAppComponent" + let path = "^->MockAppComponent" __DependencyProviderRegistry.instance.registerDependencyProviderFactory(for: path) {_ in return EmptyDependencyProvider() } @@ -35,7 +35,7 @@ class DependencyProviderRegistryTests: XCTestCase { func test_registerProviderFactory_verifyRetrievingProvider_verifyDependencyReference() { let expectedProvider = MockRootDependencyProvider() - let path = "^->NeedleFoundationTests.MockAppComponent->NeedleFoundationTests.MockRootComponent" + let path = "^->MockAppComponent->MockRootComponent" __DependencyProviderRegistry.instance.registerDependencyProviderFactory(for: path) { (component: ComponentType) -> AnyObject in return expectedProvider }