Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '11.0'
platform :ios, '13.0'
use_frameworks!

target 'PropertyInjector_Example' do
Expand All @@ -7,7 +7,7 @@ target 'PropertyInjector_Example' do
target 'PropertyInjector_Tests' do
inherit! :search_paths

pod 'Quick', '~> 1.2.0'
pod 'Nimble', '~> 7.0'
pod 'Quick', '~> 7.3'
pod 'Nimble', '~> 13.0'
end
end
20 changes: 10 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PODS:
- Nimble (7.3.4)
- PropertyInjector (0.0.5)
- Quick (1.2.0)
- Nimble (13.0.0)
- PropertyInjector (0.0.11)
- Quick (7.3.0)

DEPENDENCIES:
- Nimble (~> 7.0)
- Nimble (~> 13.0)
- PropertyInjector (from `../`)
- Quick (~> 1.2.0)
- Quick (~> 7.3)

SPEC REPOS:
trunk:
Expand All @@ -18,10 +18,10 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
PropertyInjector: c017b64e27727c1948e693d8dd141a64cb23a8fe
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
Nimble: 97d90931cca412a23224ff29e258809f75c258f7
PropertyInjector: a4e9996a307588f21ac48e9c083951916bcc6098
Quick: d32871931c05547cb4e0bc9009d66a18b50d8558

PODFILE CHECKSUM: b2b3d69c84075b0f90f75676d91d212b149a9a4d
PODFILE CHECKSUM: 1b4cc00efb7dd5dac8938d4936c5f959a45bf180

COCOAPODS: 1.9.3
COCOAPODS: 1.10.1
14 changes: 7 additions & 7 deletions Example/Pods/Local Podspecs/PropertyInjector.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Example/PropertyInjector.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
210BABBE2AE56B6D00641DB4 /* Pods_PropertyInjector_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 758A7C8295F68F44E95E1D16 /* Pods_PropertyInjector_Example.framework */; };
4C742F0C24DEF025003531E8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4C742F0B24DEF025003531E8 /* Main.storyboard */; };
4C742F0E24DEF1E1003531E8 /* DependencyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C742F0D24DEF1E1003531E8 /* DependencyManager.swift */; };
4C742F1C24DEF5A7003531E8 /* Dependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C742F1B24DEF5A7003531E8 /* Dependencies.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
607FACEC1AFB9204008FA782 /* PropertyInjectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* PropertyInjectorTests.swift */; };
AA0FD559196533EE2D5D5019 /* Pods_PropertyInjector_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C54194E9FF47E0B5520F1CF5 /* Pods_PropertyInjector_Tests.framework */; };
DDA312EDD41909C86153D0A5 /* Pods_PropertyInjector_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 758A7C8295F68F44E95E1D16 /* Pods_PropertyInjector_Example.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -54,7 +54,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DDA312EDD41909C86153D0A5 /* Pods_PropertyInjector_Example.framework in Frameworks */,
210BABBE2AE56B6D00641DB4 /* Pods_PropertyInjector_Example.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -213,6 +213,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = YBCCTWH2WW;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
Expand Down Expand Up @@ -477,8 +478,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 4553FB0CDCD40B191E3E5018 /* Pods-PropertyInjector_Example.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = YBCCTWH2WW;
INFOPLIST_FILE = PropertyInjector/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -492,8 +494,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = B41BD6F007D0F2ED7994DE46 /* Pods-PropertyInjector_Example.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = YBCCTWH2WW;
INFOPLIST_FILE = PropertyInjector/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -516,6 +519,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -534,6 +538,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
59 changes: 30 additions & 29 deletions Example/Tests/PropertyInjectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,103 +23,104 @@ class MockService: Service {
}

class PropertyInjectorTests: QuickSpec {
override func spec() {


override class func spec() {

beforeEach {
DependencyResolver.clear()
}

describe("resolving") {

it("protocol") {
DependencyResolver.register {
$0.singleton(Useful.self, Service())
}

let service: Useful = DependencyResolver.resolve()

expect(service).to(beAKindOf(Useful.self))
expect(service).to(beAKindOf(Service.self))
}

it("class") {
DependencyResolver.register {
$0.factory(Service.self, Service())
}

let service: Service = DependencyResolver.resolve()

expect(service).to(beAKindOf(Service.self))
}

it("class using shortcut method") {
DependencyResolver.register {
$0.factory(Service())
}

let service: Service = DependencyResolver.resolve()

expect(service).to(beAKindOf(Service.self))
}

it("works for optionals too") {
DependencyResolver.register {
$0.factory(Service())
}

let service: Service? = DependencyResolver.resolve()
let service2: Service! = DependencyResolver.resolve()

expect(service).to(beAKindOf(Service.self))
expect(service2).to(beAKindOf(Service.self))
}

it("mocked dependencies") {
DependencyResolver.register {
$0.singleton(Service.self, Service())
}
DependencyResolver.register {
$0.singleton(Service.self, MockService())
}

let service: Service = DependencyResolver.resolve()

expect(service).to(beAKindOf(MockService.self))
expect(service.getValue()).to(equal(MockService.anotherValue))
}

it("crashes if the dependency is not registered") {
expect(expression: { () -> Void in
expect({ () -> Void in
let _: Service = DependencyResolver.resolve()
}).to(throwAssertion())
}

}

describe("resolution strategy is correct for") {

it("singleton") {
DependencyResolver.register {
$0.singleton(Useful.self, Service())
$0.singleton(Service.self, Service())
}
let service1: Useful = DependencyResolver.resolve()
let service2: Useful = DependencyResolver.resolve()

let service1: Service = DependencyResolver.resolve()
let service2: Service = DependencyResolver.resolve()

expect(service1) === service2
}

it("factory") {
DependencyResolver.register {
$0.factory(Useful.self, Service())
$0.factory(Service.self, Service())
}
let service1: Useful = DependencyResolver.resolve()
let service2: Useful = DependencyResolver.resolve()

let service1: Service = DependencyResolver.resolve()
let service2: Service = DependencyResolver.resolve()

expect(service1) !== service2
}

}
}
}
6 changes: 3 additions & 3 deletions PropertyInjector.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'PropertyInjector'
s.version = '0.0.10'
s.version = '0.0.11'
s.summary = 'Property dependency injection framework for Swift.'

# This description is used to generate tags and improve search results.
Expand All @@ -26,7 +26,7 @@ Declare your dependencies and use them as properties in your classes.
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Stan Feldman' => 'stanislavfeldman@gmail.com' }
s.source = { :git => 'https://github.com/stanfeldman/PropertyInjector.git', :tag => s.version.to_s }
s.swift_version = '5.1'
s.ios.deployment_target = '11.0'
s.swift_version = '5.5'
s.ios.deployment_target = '13.0'
s.source_files = 'PropertyInjector/Classes/**/*'
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
```
*/
public class DependencyResolver {
public actor DependencyResolver {

private static var dependencyDefinitions = [String: DependencyDefinition]()
private static var dependencyDefinitionsWithParameters = [String: DependencyDefinitionWithParameters]()
Expand Down